Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:21:07+00:00 2026-06-12T05:21:07+00:00

I have been unable to use calcOpticalFlowPyrLK with MatOfPoint2f. I declared my types as

  • 0

I have been unable to use calcOpticalFlowPyrLK with MatOfPoint2f. I declared my types as follows:

private Mat mPreviousGray;                  // previous gray-level image
private List<MatOfPoint2f> points;          // tracked features
private MatOfPoint initial;                 // initial position of tracked points

And use the following to find and track features
(My code is based on a sample optical flow application in C++ by Robert Laganiere.)

// Called whenever a new frame m is captured
private void OpticalFlow(Mat m, int maxDetectionCount, double qualityLevel,
    double minDistance) {

    if (points.get(0).total() < maxDetectionCount/2)                // Check if new points need to be added
    {
        // maxDetectionCount = 500
        // qualityLevel = 0.01
        // minDistance = 10
        Imgproc.goodFeaturesToTrack(m, initial, maxDetectionCount, qualityLevel, minDistance);

        // add the detected features to the currently tracked features
        points.get(0).push_back(initial);
        // Have checked length of points.get(0), is not zero.
    }

    // for first image of the sequence
    if(mPreviousGray.empty())
        m.copyTo(mPreviousGray);

    if( points.get(0).total() > 0 )   // EMG - 09/22/11 - fix optical flow crashing bug 
    {       
        // 2. track features
        Video.calcOpticalFlowPyrLK(mPreviousGray, m, // 2 consecutive images
                points.get(0), // input point position in first image
                points.get(1), // output point postion in the second image
                status,    // tracking success
                error);      // tracking error
    }

    ...

    m.copyTo(mPreviousGray);

    ...
}

Previously, variable points was of type List<List<Point>> and I would convert between the types by instantiating a MatOfPoint2f with fromList and passing that to calcOpticalFlowPyrLK.

However, I wanted to no longer do that, because this conversion from and to lists loses the correspondence between points in initial and points. I want to preserve this correspondence, so I can draw optical flow lines by iterating over the items in both matrices simultaneously.

Unfortunately, now I have the following assertion failure:

09-24 10:04:30.400: E/cv::error()(8216): OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in void cv::calcOpticalFlowPyrLK(const cv::_InputArray&, const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, const cv::_OutputArray&, const cv::_OutputArray&, cv::Size, int, cv::TermCriteria, int, double), file X:\Dev\git\opencv-2.4\modules\video\src\lkpyramid.cpp, line 593
09-24 10:04:30.400: E/AndroidRuntime(8216): FATAL EXCEPTION: Thread-321
09-24 10:04:30.400: E/AndroidRuntime(8216): CvException [org.opencv.core.CvException: X:\Dev\git\opencv-2.4\modules\video\src\lkpyramid.cpp:593: error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function void cv::calcOpticalFlowPyrLK(const cv::_InputArray&, const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, const cv::_OutputArray&, const cv::_OutputArray&, cv::Size, int, cv::TermCriteria, int, double)
09-24 10:04:30.400: E/AndroidRuntime(8216): ]
09-24 10:04:30.400: E/AndroidRuntime(8216):     at org.opencv.video.Video.calcOpticalFlowPyrLK_2(Native Method)
09-24 10:04:30.400: E/AndroidRuntime(8216):     at org.opencv.video.Video.calcOpticalFlowPyrLK(Video.java:445)

Strangely enough, if I add this assertion myself, before calling calcOpticalFlowPyrLK, it does not fail.

I’m hoping someone can help me figure out where the real problem lies, and how I can preserve this relationship between the tracked points between frames.

Edit: I’ve discovered what needs to be done to avoid this assertion error, and the application then behaves correctly, but:

  • I don’t know why.
  • I have a similar problem now for Calib3d.solvePnP, but applying convertTo to the imagePoints and objectPoints does not solve the problem here, neither with CvType.CV_32FC2, nor CvType.CV_32F or CvType.CV_64F

To correct the assertion failure in case of calcOpticalFlowPyrLK, I’ve changed points.get(0).push_back(initial); to the following:

Imgproc.goodFeaturesToTrack(m, initial, maxDetectionCount, qualityLevel, minDistance);

MatOfPoint2f initial2f = new MatOfPoint2f();
initial.convertTo(initial2f, CvType.CV_32FC2);
// add the detected features to the currently tracked features
trackedpoints.get(0).push_back(initial2f);

So my question has changed to: Can someone explain the general case for me, so that I know how to solve also my problem with Calib3d.solvePnP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:21:08+00:00Added an answer on June 12, 2026 at 5:21 am

    calcOpticalFlowPyrLK point parameters are of type MatOfPoint2f which internally is CV_32FC2.

    solvePnP first parameter is MatOfPoint3f which internally is CV_32FC3. Try to convert to that to see if it fixes.

    Some opencv functions are expecting specific Mat types, I guess for efficiency reasons you have to manually choose the right ones, instead of opencv guessing/converting automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since I upgraded my iPhone to 5.1 I have been unable to use it
I have been unable to find any documentation on the .build method in Rails
I have been unable to find any decent documentation on this function. The code
I have been unable to find any documentation on properly closing database connections in
I have been unable to locate any information on compatibility with Visual Studio 2003
I have been researching intently and have been unable to find a solution to
I have need to return multiple results from a subquery and have been unable
After an extensive search I have been unable to find any information on this
I have only recently started using CakePHP and have been unable to get validation
So I have been intrigued by the ?? operator, but have still been unable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.