calcOpticalFlowPyrLK never returns in Java call

asked 2014-08-22 13:56:43 -0500

valder gravatar image

Hello, I've been trying to port a C library into Java for my Android project. I'm not making a whole lot of progress. I'm taking in a video file and trying to do some analysis on the frames. I'm able to get all the way up to the point where I call Video.calcOpticalFlowPyrLK(). At this point the code just never returns. No exception is thrown or any messages printed to the log. Any suggestions? I've included some code snippets .

Thanks,

void DetectFrame(Mat currFrame)
{
    TermCriteria termcrit = new TermCriteria(TermCriteria.MAX_ITER | TermCriteria.EPS, 20, 0.03);
    Size subPixWinSize = new Size(10,10), winSize = new Size(31,31);

    Imgproc.cvtColor(currFrame, curr_, Imgproc.COLOR_BGR2GRAY);
    Imgproc.goodFeaturesToTrack(curr_, initialPoints, max_corners, 0.01, 10);

    Log.d(MotionTracker.class.getCanonicalName(), "features found: " + initialPoints.total());

    nextPoints = new MatOfPoint2f( initialPoints.toArray() );
    Log.d(TAG, "Number of features found : " + nextPoints.total());

    if(nextPoints.total() != 0) //Some weird problem that causes features to be found !!!
    {
        Size zeroZone = new Size(-1, -1);
        Imgproc.cornerSubPix(curr_, nextPoints, subPixWinSize, zeroZone, termcrit);
        Log.d(TAG, "sub pixel count: " + nextPoints.total());

        if(prev_.empty())
        {
            swapMatOfPoint2f();
            swapMat();
        }
    }
    else {
        Log.d(TAG, "No features found !");
    }
}


public boolean TrackFrame(Mat trackedFrame) {
    int i=0, k;
    MatOfPoint2f pt;
    TermCriteria termCriteria = new TermCriteria(TermCriteria.EPS | TermCriteria.MAX_ITER, 20, 0.03);
    Size subPixWinSize = new Size(10,10);
    Size winSize = new Size(5,5);
    if (prevPoints.empty() || (frame_count_ % 12) == 0) {
        DetectFrame(trackedFrame);
    }
    else {
        try {
             Imgproc.cvtColor(trackedFrame, curr_, Imgproc.COLOR_BGR2GRAY);
              Video.calcOpticalFlowPyrLK(prev_, curr_, prevPoints, nextPoints, status_, err_);

        } catch (Exception ex) {
            // do something with the exception
             ......
        }
edit retag flag offensive close merge delete