Research Article

CAMeL: A Self-Adaptive Framework for Enriching Context-Aware Middlewares with Machine Learning Capabilities

Listing 1

iPOJO module capable of acquiring a frame from a camera using OpenCV.
(1)@Validate
(2)public void start () throws Exception {
(3) Thread t = new Thread (this);
(4)t.start ();
(5)}
(6)@Invalidate
(7)public void stop () {
(8) stop = true;
(9)}
(10)public void run () {
(11) FrameGrabber grabber = null;
(12)try {
(13)  ProducerTemplate producer = context.getContext ().createProducerTemplate ();
(14)  //image grabbing via OpenCV API
(15)  grabber = FrameGrabber.createDefault (0);
(16)  grabber.start ();
(17)  IplImage grabbedImage = grabber.grab ();
(18)  while (stop == false && (grabbedImage = grabber.grab()) ! = null) {
(19)   //… creating imageData object
(20)   //send data to the “image” queue
(21)   producer.sendBody (imageSedaQueue, imageData);
(22)  }
(23)  grabber.stop ();
(24) } catch (Exception e) {
(25)  //… exception handling
(26) }
(27)}