Cv :: goodFeaturesToTrack does not return any functions

I try to use cv::calcOpticalFlowPyrLK, but sometimes the internal statement in this function fails. Statement npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0. I am using OpenCV 2.3.1. The source code for this function is available here .

I find it difficult to wrap my head around my code, especially due to my limited experience with computer graphics and the lack of comments. Why does this statement work and what does he say about my problem?

Edit : I call the function as follows:

cv::calcOpticalFlowPyrLK(curBwFrame, prvFrame, features, newFeatures, trackingStatus, errors);

I found out that a vector featuresthat was obtained by calling cv::goodFeaturesToTrack(curBwFrame, features, 5, 0.2, 0.5, skinMask);with a non-blank mask, which seems large enough and a valid image, does not contain any functions. How can this happen?

curBwFrame

curBwFrame

skinMask

skinMask

, :

#include <vector>
#include <cassert>
#include <opencv2\opencv.hpp>
using std::vector;
using namespace cv;

int main() {
    vector<Point2f> features;
    cv::Mat curBwFrame = imread("curBwFrame.png");
    cv::cvtColor(curBwFrame, curBwFrame, CV_RGB2GRAY);
    imwrite("test.png", curBwFrame);

    cv::Mat skinMask = imread("skinMask.png");
    cv::cvtColor(skinMask, skinMask, CV_RGB2GRAY);
    imwrite("test.png", skinMask);

    cv::goodFeaturesToTrack(curBwFrame, features, 5, 0.2, 0.5, skinMask);
    assert(features.size() > 0);

    return 0;
}
+5
4

. OpenCV 2.3.2 ( 2.3.1) :

void goodFeaturesToTrack(InputArray image, OutputArray corners, int maxCorners, double qualityLevel, double minDistance, InputArray mask=noArray(), int blockSize=3, bool useHarrisDetector=false, double k=0.04 )

:

  • image - 8- 32- .
  • - .
  • maxCorners - . , , .
  • qualityLevel - , . , (. cornerMinEigenVal()) (. cornerHarris()). , . , measure = 1500, qualityLevel = 0.01, 15 .
  • minDistance. .
  • - . ( CV_8UC1 , ), , .
  • blockSize - . cornerEigenValsAndVecs().
  • useHarrisDetector - , , Harris (. cornerHarris()) cornerMinEigenVal().
  • k - .

qualityLevel minDistance, .

+4

goodFeaturesToTrack , , ? , - , , , goodFeaturesToTrack .

ORB FAST goodFeaturesToTrack. ORB calcOpticalFlowPyrLK ( ).

. , , , , , . ORB , .

+1

? cv:: transform . , 0 255. .

0
source

If your code is similar to this:

 Imgproc.goodFeaturesToTrack(mCurrentFrame, initial, NUMBER_OF_FEATURES, 0.1, 10); 
 //The OpenCV opticalFlow will crash if the feature vector does not include any elements
 if (initial.elemSize() == 0) {
     return;
 }
 initial.convertTo(mPrevPts, CvType.CV_32FC2);

 Video.calcOpticalFlowPyrLK(mPreviousFrame, mCurrentFrame, mPrevPts, mNextPts, status,err);

Make sure that you do not forget the operator that checks the size of the vector function (initial.elemSize () == 0).

If this vector is empty, the conversion from the Matrix of a point to floating points performed in the initial.convertTo () line will not occur, and the statement will be displayed when calOpticalFlowPyrLK is called

0
source

All Articles