cv::Mat img1 = cv::imread(“/home/hfm/slam/CLionProjects/rlof/image/1.png”);
cv::Mat img2 = cv::imread(“/home/hfm/slam/CLionProjects/rlof/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);
// 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 do I keep getting errors :point1 size150 point2 size150
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.2.0) …/contrib/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.