arduino - Contour position with "findcontour" opencv on processing -


i'm working on project have use webcam, arduino, raspberry , ir proximity sensor. arrived of google. have big problem that's think. i'm using opencv library on processing , i'd contours webcam in center of sketch. arrived move video , not contours here's code. hope you'll me :)

all best

alexandre

//////////////////////////////////////////// ////////////////////////////////// libraries ////////////////////////////////////////////  import processing.serial.*; import gab.opencv.*; import processing.video.*;     ///////////////////////////////////////////////// ////////////////////////////////// initialization /////////////////////////////////////////////////  movie mymovie; capture video; opencv opencv; contour contour;     //////////////////////////////////////////// ////////////////////////////////// variables ////////////////////////////////////////////  int lf = 10;    // linefeed in ascii string mystring = null; serial myport;  // serial port int sensorvalue = 0; int x = 300;     ///////////////////////////////////////////// ////////////////////////////////// void setup /////////////////////////////////////////////  void setup() {   size(1280, 1024);   // list available serial ports   printarray(serial.list());   // open port using @ rate want:   myport = new serial(this, serial.list()[1], 9600);   myport.clear();   // throw out first reading, in case started reading    // in middle of string sender.   mystring = myport.readstringuntil(lf);   mystring = null;   opencv = new opencv(this, 720, 480);   video = new capture(this, 720, 480);   mymovie = new movie(this, "visage.mov");   opencv.startbackgroundsubtraction(5, 3, 0.5);   mymovie.loop(); }     //////////////////////////////////////////// ////////////////////////////////// void draw ////////////////////////////////////////////  void draw() {    image(mymovie, 0, 0);   image(video, 20, 20);   //tint(150, 20);   nofill();   stroke(255, 0, 0);   strokeweight(1);      // check if there new on serial port   while (myport.available() > 0) {     // store data in mystring      mystring = myport.readstringuntil(lf);     // check if have     if (mystring != null) {       mystring = mystring.trim(); // let's remove whitespace characters       // if have @ least 1 character...       if (mystring.length() > 0) {         println(mystring); // print out data received         // if received number (e.g. 123) store in sensorvalue, sill use change background color.          try {           sensorvalue = integer.parseint(mystring);         }          catch(exception e) {         }       }     }   }   if (x < sensorvalue) {     video.start();     opencv.loadimage(video);    }    if (x > sensorvalue) {     image(mymovie, 0, 0);   }    opencv.updatebackground();   opencv.dilate();   opencv.erode();    (contour contour : opencv.findcontours()) {     contour.draw();   }  }     ////////////////////////////////////////////// ////////////////////////////////// void custom //////////////////////////////////////////////  void captureevent(capture video) {   video.read(); // affiche l'image de la webcam }  void movieevent(movie mymovie) {   mymovie.read(); } 

one approach use call translate() function move origin of canvas before call contour.draw(). this:

translate(movex, movey);  (contour contour : opencv.findcontours()) {     contour.draw(); } 

what use movex , movey depends entirely on you're trying do. might use whatever position you're using draw video (if want contours displayed on top of video), or might use width/2 , height/2 (maybe minus bit center contours).

more info can found in the reference. play bunch of different values, , post mcve if stuck. luck.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -