OpenCV Error: Assertion failed (prevPyr[level * lvlStep1].size() == nextPyr[level * lvlStep2].size()) in void cv::calcOpticalFlowPyrLK
I am working on 2 images, on the first one i found goodFeaturesToTrack and draw it then on it, i am trying to to tracking with that to the second image but the line of calling calcOpticalFlowPyrLK gets an error:
error(): OpenCV Error: Assertion failed (prevPyr[level * lvlStep1].size() == nextPyr[level * lvlStep2].size()) in void cv::calcOpticalFlowPyrLK(InputArray, InputArray, InputArray, InputOutputArray, OutputArray, OutputArray, Size, int, cv::TermCriteria, int, double), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/video/src/lkpyramid.cpp, line 979
And i do not understand what the proble, is.
MatOfPoint2f prevPts = new MatOfPoint2f();
MatOfPoint2f nextPts = new MatOfPoint2f();
MatOfByte status = new MatOfByte();
MatOfFloat err = new MatOfFloat();
//when to stop
TermCriteria optical_flow_termination_criteria=new TermCriteria();
optical_flow_termination_criteria.epsilon=0.3;
optical_flow_termination_criteria.maxCount =20;
int maxlevel = 2;
Size s = new Size( 21, 21);
MatOfPoint corners = new MatOfPoint();
Imgproc.goodFeaturesToTrack(tmp,corners,maxCorners,qualityLevel,minDistance,newMat(),blockSize,
useHarrisDetector,k);
org.opencv.core.Point[] points = corners.toArray();
for (org.opencv.core.Point p : points) {
Core.circle(tmp2, p, 8, circleColor);
}
corners.convertTo(prevPts, CvType.CV_32FC2);
Video.calcOpticalFlowPyrLK(tmp, secondtmp, prevPts, nextPts, status, err,s,maxlevel,optical_flow_termination_criteria,2,1);
Thank in advance!!
can you take a look at your
tmp, secondtmp
images ? it seems, they're not both valid.@berak They seem to be ok, with tmp i was able to find goodFeaturesToTrack and draw it on the image, and second tmp seems to be the same.
I encountered the same error. It was because the the images didn't had the same size, width and height. The pyramid images are just a series of scaled down images of the original images, and if the original images didn't had the same size, any two corresponding pyramid images will also be of different size.