OpenCV:将cvGoodFeaturesToTrack与C ++ mat变量一起使用 [英] OpenCV: Using cvGoodFeaturesToTrack with C++ mat variable

查看:163
本文介绍了OpenCV:将cvGoodFeaturesToTrack与C ++ mat变量一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio 2010中使用cvGoodFeatureToTrack函数,图像类型为Mat.我见过的大多数示例都使用IplImage指针. 现在我有这个:

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!

推荐答案

作为起点,如果仍然使用C ++(例如您使用cv::Matcv::cvtColor的建议),那么为什么不使用C ++接口呢?也一样?

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?

这意味着使用 cv::GoodFeaturesToTrackDetector ,它们可以在cv::Mat和朋友,而不是从cv::MatIplImage*进行不必要的投射.

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);

这篇关于OpenCV:将cvGoodFeaturesToTrack与C ++ mat变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆