c++ - OpenCV goodFeaturesToTrack's status are zeros -
trying implement optical flow ios opencv 3.1 .
i built basic stuff shown in below code , features points goodfeaturestotrack
thing no point being tracked, , status
results zeros (not tracked).
cv::mat gray; // current gray-level image cv::mat gray_prev; std::vector<cv::point2f> features; // detected features std::vector<cv::point2f> newfeatures; std::vector<uchar> status; // status of tracked features std::vector<float> err; // error in tracking cv::termcriteria _termcrit = cv::termcriteria(cv::termcriteria::count|cv::termcriteria::eps,20,0.03); -(void)processimage:(cv::mat&)image { //-------------------- optical flow --------------------- cv::cvtcolor(image, gray, cv_bgr2gray); if(gray_prev.empty()) { gray.copyto(gray_prev); } cv::goodfeaturestotrack(gray, features, 20, 0.01, 10); cv::calcopticalflowpyrlk(gray_prev, gray, features, newfeatures, status, err, cv::size(10, 10), 3, _termcrit, 0, 0.001); // draw circles features points (int = 0; < features.size(); i++) { circle(image, features[i], 10, cv::scalar(250,250,250)); } (int y = 0; y < status.size(); y++) { nslog(@"status: %d", status[y]); // 0 } std::swap(newfeatures, features); cv::swap(gray_prev, gray); }
you should call
cv::goodfeaturestotrack(gray, features, 20, 0.01, 10);
only first initialisation of features list, , not on every cycle. doing reseting features list match current frame on every cycle there no displacement in features.
also, if want displacement between 2 frames should call
cv::goodfeaturestotrack(**gray_prev**, features ....
Comments
Post a Comment