3

So I'm trying to use the calcCopticalFlowPyrLK method and it keeps throwing an assertion fail:

OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) 

And checkVector checks that the input Matrix is 2 channel and has a color depth of CV_32F. My input is a Mat with 4 channels and a color depth of CV_8U. When I try to convert it it fails to change every time. I used

Mat prevFrame; // The input Mat. Grabbed from CvCameraViewFrame. Converted to rgb

Mat prev = new Mat(rows,cols, CvType.CV_32F);
Imgproc.cvtColor(prevFrame, prev, Imgproc.COLOR_BGRA2GRAY);
prev.convertTo(prev, CvType.CV_32F);

But when I check the afterward prev has the correct depth (CV_32F) but only 1 element channel. I've been struggling with this for hours and I can't figure out what the issue is

Jave
  • 31,598
  • 14
  • 77
  • 90
Jared Joke
  • 1,226
  • 2
  • 18
  • 29

1 Answers1

1

The assertion has failed on the prevPtsMat vector which is the third argument to the calcOpticalFlowPyrLK call. It seems that the matrix you are defining here is the first argument and that should be a single channel image as it already is. http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html

I suppose you are using a points array for the third argument and you might need to explicitly create a MatOfPoint2f() for the points array. I think this has been described in: Android: Using calcOpticalFlowPyrLK with MatOfPoint2f

Community
  • 1
  • 1