OpenCV: Using cvGoodFeaturesToTrack with C++ mat variable

谁说我不能喝 提交于 2019-12-20 07:36:06

问题


I am trying to use the cvGoodFeatureToTrack function in Visual Studio 2010 with the image type as Mat. Most of the examples I have seen use the IplImage pointer. Right now I have this:

int w, h; // video frame size

Mat grayFrame;
Mat eigImage;
Mat tempImage;
const int MAX_CORNERS = 10;
CvPoint2D32f corners[MAX_CORNERS] = {0};
int corner_count = MAX_CORNERS;
double quality_level = 0.1;
double min_distance = 10;
int eig_block_size = 3;
int use_harris = false;

w = CurrFrame.size().width;
h = CurrFrame.size().height;
cvtColor(CurrFrame, grayFrame, CV_BGR2GRAY);
cvGoodFeaturesToTrack(&grayFrame,
                      &eigImage,
                      &tempImage,
                      corners,
                      &corner_count,
                      quality_level,
                      min_distance,
                      NULL,
                      eig_block_size,
                      use_harris);

It compiles but gives me a memory access violation. Help!


回答1:


As a starting point, if using C++ anyway (like your use of cv::Mat and cv::cvtColor suggests), then why not use C++ interface for the rest, too?

This would mean the use of cv::goodFeaturesToTrack or a cv::GoodFeaturesToTrackDetector, which are made to work on cv::Mat and friends instead of making unneccessary casts from cv::Mat to IplImage*.

cv::Mat grayFrame;
std::vector<cv::Point2f> corners;
double quality_level = 0.1;
double min_distance = 10;
int eig_block_size = 3;
int use_harris = false;

const int MAX_CORNERS = 10;
cv::cvtColor(CurrFrame, grayFrame, CV_BGR2GRAY);
cv::goodFeaturesToTrack(grayFrame,
                        corners,
                        MAX_CORNERS,
                        quality_level,
                        min_distance,
                        cv::noArray(), 
                        eig_block_size,
                        use_harris);


来源:https://stackoverflow.com/questions/12635390/opencv-using-cvgoodfeaturestotrack-with-c-mat-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!