Skip to content

RLOF OptFlow Bug Fix #3423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2023
Merged

RLOF OptFlow Bug Fix #3423

merged 3 commits into from
Jan 24, 2023

Conversation

matijazigic
Copy link
Contributor

@matijazigic matijazigic commented Jan 17, 2023

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

The bug has already been reported and explained on the OpenCV forum:

The bug is manifested only if 'UseInitialFlow' is set to true and 'ForwardBackwardThreshold' > 0 (enabled).

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@asmorkalov asmorkalov merged commit 5a35eb1 into opencv:4.x Jan 24, 2023
@alalek alalek mentioned this pull request Jan 28, 2023
@asmorkalov asmorkalov mentioned this pull request May 31, 2023
@rangingwaves
Copy link

cv::Mat img1 = cv::imread("./image/1.png");
cv::Mat img2 = cv::imread("./image/2.png");
if (img1.empty() || img2.empty()) {
std::cerr << "Error: Could not open images." << std::endl;
return -1;
}

std::vector<cv::Point2f> points1, points2;
cv::Mat img1_gray;
cv::cvtColor(img1, img1_gray, cv::COLOR_BGR2GRAY);
cv::goodFeaturesToTrack(img1_gray, points1, 150, 0.01, 10);

cv::Ptr<cv::optflow::RLOFOpticalFlowParameter> rlof_param = cv::optflow::RLOFOpticalFlowParameter::create();
rlof_param->useInitialFlow= true;

std::vector<uchar> status;
std::vector<float> err;
points2 = points1; 
std::cout<<"point1 size"<<points1.size()<<"   "<<"point2 size"<<points2.size()<<std::endl;
cv::optflow::calcOpticalFlowSparseRLOF(img1, img2, points1, points2, status, err, rlof_param, 0);

// cv::calcOpticalFlowPyrLK(img1, img2, points1, points2, status, err, cv::Size(21, 21), 1,cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 30, 0.01), cv::OPTFLOW_USE_INITIAL_FLOW);

Why am I still encountering this error:
the Print result is point1 size150 point2 size150,
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.10.0) /home/hfm/slam_lib/opencv-4.10.0/opencv_contrib-4.10.0/modules/optflow/src/rlof/rlof_localflow.cpp:402: error: (-215:Assertion failed) nextPtsMat.checkVector(2, CV_32F, true) == npoints in function 'calcLocalOpticalFlowCore'。I used // cv::calcOpticalFlowPyrLK(img1, img2, points1, points2, status, err, cv::Size(21, 21), 1,cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 30, 0.01), cv::OPTFLOW_USE_INITIAL_FLOW);and there was no such error. Did I make a mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants