Updated by Vladislav Vinogradov about 11 years ago

The function of @buildOpticalFlowPyramid@ buildOpticalFlowPyramid and @calcOpticalFlowPyrLK@ calcOpticalFlowPyrLK in OpenCV-2.4.8-android-sdk is:

<pre>
public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel)

public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold)
</pre>



If I just use the image as the input of @calcOpticalFlowPyrLK@, calcOpticalFlowPyrLK, not using pyramid, it works well. But If I use @buildOpticalFlowPyramid@ buildOpticalFlowPyramid to build bulid a pyramid as input of @calcOpticalFlowPyrLK@. calcOpticalFlowPyrLK. The @List<Mat> pyramid@ List<Mat> pyramid is not applicable for @Mat prevImg@. Mat prevImg.

If I declare the pyramid as @vector<Mat>@, @buildOpticalFlowPyramid@ vector<Mat>, buildOpticalFlowPyramid works well, but the app will be forced to stop whenever call @calcOpticalFlowPyrLK@. calcOpticalFlowPyrLK.

Here is parts of the code.

<pre>
MatOfByte status = new MatOfByte();
int maxlevel=2;

Mat prev = new Mat(mRgba.size(),CvType.CV_8UC1);
Mat curr = new Mat(mRgba.size(),CvType.CV_8UC1);
List<Mat> pyramid1= new ArrayList<Mat>(maxlevel);
List<Mat> pyramid2= new ArrayList<Mat>(maxlevel);

Mat pyramid3 = new Mat();
Mat pyramid4 = new Mat();

MatOfPoint2f featurestracked = new MatOfPoint2f();
MatOfFloat err = new MatOfFloat();

int i,count;
TermCriteria optical_flow_termination_criteria =new TermCriteria();

optical_flow_termination_criteria.epsilon =.03;
optical_flow_termination_criteria.maxCount = 20;
Size winSize = new Size(21,21);

Imgproc.cvtColor(hp.TrackingFrame, prev, Imgproc.COLOR_RGBA2GRAY,0);

Imgproc.cvtColor(mRgba, curr, Imgproc.COLOR_RGBA2GRAY,0);

//Build pyramid
int level1= Video.buildOpticalFlowPyramid(prev, pyramid1, winSize, maxlevel);
int level2 = Video.buildOpticalFlowPyramid(curr, pyramid2, winSize, maxlevel);

pyramid3 = Converters.vector_Mat_to_Mat(pyramid1);
pyramid4 = Converters.vector_Mat_to_Mat(pyramid2);

MatOfPoint2f features_next2f = new MatOfPoint2f(hp.features_next.toArray());

Video.calcOpticalFlowPyrLK(pyramid3, pyramid4,features_next2f,featurestracked,status,err, winSize,maxlevel,optical_flow_termination_criteria, 0, 0.001);
</pre>

Back