I’m using ofxopenCv to calculate the optical flow of a videoGrabber. I am finding this more accurate than using the contour finder.
Currently, I have a program that draws the optical flow of the video with vectors when the motion passes a certain threshold. What I want to do is set each area of motion vectors into a bounding box and then get the centroid of each area of motion and track that motion in a variable. I was looking at polyline, but I couldn’t get it working.
This is part of my draw function where the if statement at the end only draws vectors based on the threshold.
The full code can be seen in the attachment.
Any ideas would be appreciated.
if (calculatedFlow){
ofSetColor( 255, 255, 255 );
video.draw( 0, 0);
int w = gray1.width;
int h = gray1.height;
//Input images + optical flow
ofPushMatrix();
ofScale( 4, 4 );
//Optical flow
float *flowXPixels = flowX.getPixelsAsFloats();
float *flowYPixels = flowY.getPixelsAsFloats();
ofSetColor( 0, 0, 255 );
for (int y=0; y<h; y+=5) {
for (int x=0; x<w; x+=5) {
float fx = flowXPixels[ x + w * y ];
float fy = flowYPixels[ x + w * y ];
//Draw only long vectors
if ( fabs( fx ) + fabs( fy ) > .5 ) {
//Draws vectors if past threshold of 0.5
ofDrawRectangle( x-0.5, y-0.5, 1, 1 );
ofDrawLine( x, y, x + fx, y + fy );
}
}
}
}
opticalCode.zip (2.7 KB)