Euglena tracking and OSC broadcasting: Difference between revisions

From Medien Wiki
Line 30: Line 30:
       if (a > minArea && wh > 0.1 && wh < 10 && a < maxArea) {
       if (a > minArea && wh > 0.1 && wh < 10 && a < maxArea) {
       // ...
       // ...
</source>
=== Maintaining Euglena identity in a list (based on proximity from frame to frame), computing speed as dx, dy ===
<source lang="java">
void checkEuglena(Contour c) {
  boolean found = false;
  Rectangle r = c.getBoundingBox();
  for (Euglena e : euglenaList) {
    if (dist(e.x, e.y, r.x, r.y) < distanceThreshold) {
      e.dx = e.x - r.x;
      e.dy = e.y - r.y;
      e.x = r.x;
      e.y = r.y;
      e.found = true;
      found = true;
      break;
    }
  }
  if (!found) {
    euglenaList.add(new Euglena(r.x, r.y));
  }
}
</source>
</source>

Revision as of 09:24, 7 June 2015

Quick and dirty Euglena tracking using OpenCV, Syphon, and OSC.


Threshold based Euglena detection

opencv.loadImage(cam);

opencv.gray();
opencv.invert();
threshold = int(map(mouseX,0,width,0,255));

opencv.erode();
opencv.dilate();
    
opencv.threshold(threshold);

// ...

contours = opencv.findContours();

Skipping large/small contours

for (Contour contour : contours) {
      float a = contour.area();
      Rectangle r = contour.getBoundingBox();
      float wh = float(r.width)/float(r.height);
      if (a > minArea && wh > 0.1 && wh < 10 && a < maxArea) {
      // ...

Maintaining Euglena identity in a list (based on proximity from frame to frame), computing speed as dx, dy

void checkEuglena(Contour c) {
  boolean found = false;
  Rectangle r = c.getBoundingBox();
  for (Euglena e : euglenaList) {
    if (dist(e.x, e.y, r.x, r.y) < distanceThreshold) {
      e.dx = e.x - r.x;
      e.dy = e.y - r.y;
      e.x = r.x;
      e.y = r.y;
      e.found = true;
      found = true;
      break;
    }
  }
  if (!found) {
    euglenaList.add(new Euglena(r.x, r.y));
  }
}