Android - OpticalFlow: calcOpticalFlowPyrLK & goodFeaturesToTrack return same points

asked 2012-11-05 12:06:08 -0500 gravatar image

I'm working on an Android video stabilization application! I got some problem related with goodfeaturestotrack and calcOpticalFlowPyrLK functions 'cause the final output is the same points! I googled every single site regarding this but I wasn't able to solve it! What's wrong with my code?

mRgba1 = new Mat(height, width, CvType.CV_8UC4);
mRgba2 = new Mat(height, width, CvType.CV_8UC4);
mGray1 = new Mat(mRgba1.size(), CvType.CV_8UC1);
mGray2 = new Mat(mRgba2.size(), CvType.CV_8UC1);
mView = new Mat(height, width, CvType.CV_8UC4);
initial = new MatOfPoint();
status = new MatOfByte();
err = new MatOfFloat();
mask = new Mat(mRgba1.size(), CvType.CV_8UC1);
prevPts = new MatOfPoint2f();
nextPts = new MatOfPoint2f();
Imgproc.goodFeaturesToTrack(mGray1, initial, maxCorners, 0.01, 0.01);
initial.convertTo(prevPts, CvType.CV_32FC2);
Video.calcOpticalFlowPyrLK(mGray1, mGray2, prevPts, nextPts, status, err, winSize, 5, optical_flow_termination_criteria, 0, 1);

Then, when I show them:

Point[] pointp = prevPts.toArray();
Point[] pointn = nextPts.toArray();
for (Point px : pointp) 
{, px, 15, circleColor); }
for (Point py : pointn) 
{, py, 5, line_color); }

I got 2 different circles in the same position, and that's not good :(

edit retag flag offensive close merge delete


Do mGray1 and mGray2 have some image? Are they different from each other?

Rui Marques gravatar imageRui Marques ( 2012-11-07 10:08:43 -0500 )edit