Mat OpenCV Access Control

I am trying to learn OpenCV and being tough, I am trying to run the following algorithm:

 cv::Mat cur_features;
 cv::goodFeaturesToTrack(current_image, cur_features, 400, 0.01, 0.01);

Now, being a solid person, I am interested to see what cur_features holds ... I was expecting 400x2 cv :: Mat, but instead I got 400x1 cv :: Mat

No big, I think maybe this is a direct index. However, for LIFE me, I CANNOT extract the value from cur_features.at (0) and print it.

What am I doing wrong? I saw goodFeaturesToTrack_Demo.cpp. Some things to note in this demo that are different for mine. I tried the following calls given in the following example:

 std::cout << cur_features.size() << std::endl; // This throws a compile time error even though its in the example
 std::cout << cur_features.at<Point2f>(0).x << std::endl; //This throws a run time error.

Can someone lead me to some kind of documentation explaining how to achieve my goal? The goodFeaturesToTrack function tells you that it returns an OutputArray, which is a vector of angles but does not describe anywhere what type of angles are. Where in the documentation will I look for this answer in case I get it using other methods?


Edit: Also, what does the point Mat :: type () mean. I cannot find where to explain the return value ... I am looking for an enumeration in the documentation, but I cannot find it.

 std::cout << current_image.type() << std::endl; //This returns 0
 std::cout << cur_features.type() << std::endl; //This returns 13
+5
source share
3 answers

As a suggestion, try initializing matrices with sizes and type

 cv::Mat cur_features(400,1,CV_32_FC1); //400x1 32 bits, 1 channel
 cv::Mat cur_features2(400,1,CV_32_FC2); //400x1 32 bits, 2 channels

To get the Mata value

int pos = 0;
foat value = cur_features.at<float>(pos);
cv::Vec2f value2 = cur_features2.at<Vec2f>(pos); // for a two channel, CV_23F image

And a convenient debugging technology for Visual Studio, which helped me a lot.

  • 1- cur_features .
  • 2- QuickWatch
  • 3- :

    ( *) cur_features.data, 400

  • 4-

+5

, goodFeaturesToTrack 400x1, , , .

 cur_features.data == NULL

, C , ++.

+4

: http://opencv.itseez.com/modules/imgproc/doc/feature_detection.html

vector<Point2f> .

goodFeaturesToTrack_Demo.cpp OpenCV:

  vector<Point2f> corners;
  ...
  /// Apply corner detection
  goodFeaturesToTrack( src_gray, 
               corners,
               maxCorners,
               qualityLevel,
               minDistance,
               Mat(),
               blockSize,
               useHarrisDetector,
               k );

UPDATE: , , OutputArray . http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html 2.1 vector<Point2f>

+2

All Articles