emailconfirmed
174
edits
| No edit summary | No edit summary | ||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| == Quick and dirty Euglena tracking using OpenCV, Syphon, and OSC. == | === Quick and dirty Euglena tracking using OpenCV, Syphon, and OSC. === | ||
| Sources at GitHub: https://github.com/lscherff/biogames/tree/master/TrackEuglenaSyphonOSC | |||
| === Threshold based Euglena detection === | === Threshold based Euglena detection === | ||
| <source lang="java"> | <source lang="java"> | ||
| opencv.loadImage(cam); | opencv.loadImage(cam); | ||
| Line 9: | Line 10: | ||
| opencv.gray(); | opencv.gray(); | ||
| opencv.invert(); | opencv.invert(); | ||
| opencv.erode(); | opencv.erode(); | ||
| opencv.dilate(); | opencv.dilate(); | ||
| threshold = int(map(mouseX,0,width,0,255)); | |||
| opencv.threshold(threshold); | opencv.threshold(threshold); | ||
| Line 21: | Line 22: | ||
| </source> | </source> | ||
| === Skipping large/small contours === | === Skipping large/small/malformed contours === | ||
| <source lang="java"> | <source lang="java"> | ||
| for (Contour contour : contours) { | for (Contour contour : contours) { | ||
| Line 31: | Line 32: | ||
| </source> | </source> | ||
| === Maintaining Euglena identity in a list (based on proximity from frame to frame), computing speed as dx, dy === | === Maintaining Euglena identity in a list (based on proximity from frame to frame), computing speed as dx, dy and mean speed as mdx, mdy=== | ||
| <source lang="java"> | <source lang="java"> | ||
| Line 51: | Line 52: | ||
|      euglenaList.add(new Euglena(r.x, r.y)); |      euglenaList.add(new Euglena(r.x, r.y)); | ||
|    } |    } | ||
| } | |||
| void deleteEuglena() { | |||
|   ListIterator<Euglena> iter = euglenaList.listIterator(); | |||
|   float newmdx = 0; | |||
|   float newmdy = 0; | |||
|   while (iter.hasNext()) { | |||
|     Euglena e = iter.next(); | |||
|     if (e.found==false) iter.remove(); | |||
|     else { | |||
|       e.found = false; | |||
|       newmdx = newmdx + e.dx; | |||
|       newmdy = newmdy + e.dy; | |||
|     } | |||
|   } | |||
|   if (euglenaList.size() > 0) { | |||
|     newmdx = newmdx / euglenaList.size(); | |||
|     newmdy = newmdy / euglenaList.size(); | |||
|   } else { | |||
|     newmdx = 0; | |||
|     newmdy = 0; | |||
|   } | |||
|   mdx += (newmdx - mdx)*0.01; | |||
|   mdy += (newmdy - mdy)*0.01; | |||
| } | } | ||
| </source> | </source> | ||