OpenCV:使用函数cvGoodFeaturesToTrack时出错 [英] OpenCV: Error when using function cvGoodFeaturesToTrack

查看:122
本文介绍了OpenCV:使用函数cvGoodFeaturesToTrack时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用函数cvGoodFeaturesToTrack来查找Harris角时,会出现此错误:

  OpenCV错误:cornerEigenValsVecs中的声明失败(src.type()== CV_8UC1 || src.type()== CV_32FC1),文件/build/buildd/opencv-2.1.0/src/cv/cvcorner.cpp,第254行抛出'cv :: Exception'实例后调用终止what():/build/buildd/opencv-2.1.0/src/cv/cvcorner.cpp:254:错误:(-215)src.type()== CV_8UC1 ||src.type()==函数cornerEigenValsVecs中的CV_32FC1中止 

它可以正确编译,但是当我尝试运行它时,会出现该错误.

这是代码:

  IplImage * eig_image = 0;IplImage * temp_image = 0;IplImage * img1 = 0;img1 = cvLoadImage("im1.pgm");if(img1 == 0){printf(哦,不!");}eig_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F,1);temp_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F,1);const int MAX_CORNERS = 100;CvPoint2D32f corners [MAX_CORNERS] = {0};int corner_count = MAX_CORNERS;double quality_level = 0.1;double min_distance = 1;int eig_block_size = 3;int use_harris = true;双k = 0.4;cvGoodFeaturesToTrack(img1,eig_image,temp_image,corners,&corner_count,quality_level,min_distance,NULL,eig_block_size,use_harris,k); 

为什么会发生这种情况,我该如何解决?感谢您的帮助!

解决方案

OpenCV试图告诉您传递给cvGoodFeaturesToTrack()的图像之一(该错误实际上源自辅助函数cornerEigenValsVecs())不是所需类型为CV_8UC1或CV_32FC1.

我怀疑img1可能不是您需要的类型.img1矩阵的类型是什么?如果是彩色,则可能是CV_8UC3类型.考虑使用 cvCvtColor 使其成为灰度图像./p>

或者,您也可以最初将图像加载为灰度图像,例如:

  cvLoadImage("im1.pgm",CV_LOAD_IMAGE_GRAYSCALE); 

When I call the function cvGoodFeaturesToTrack to find Harris corners I get this error:

OpenCV Error: Assertion failed (src.type() == CV_8UC1 || src.type() == CV_32FC1) in cornerEigenValsVecs, file /build/buildd/opencv-2.1.0/src/cv/cvcorner.cpp,line 254 
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.1.0/src/cv/cvcorner.cpp:254: error: (-215) src.type() == CV_8UC1 || src.type() == CV_32FC1 in function cornerEigenValsVecs

Aborted

It compiles correctly but when I try to run it, it gives me that error.

Here is the code:

IplImage* eig_image = 0;
IplImage* temp_image = 0;

IplImage *img1 = 0;

img1 = cvLoadImage("im1.pgm");
if(img1==0) {
    printf("oh no!");
}

eig_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F, 1);

temp_image = cvCreateImage(cvGetSize(img1),IPL_DEPTH_32F, 1);


const int MAX_CORNERS = 100;
CvPoint2D32f corners[MAX_CORNERS] = {0};
int corner_count = MAX_CORNERS;
double quality_level = 0.1;
double min_distance = 1;
int eig_block_size = 3;
int use_harris = true;
double k  = .4;

cvGoodFeaturesToTrack(img1, eig_image, temp_image,corners,&corner_count,quality_level,min_distance,NULL,eig_block_size,use_harris,k);

Why is this happening and how can I fix it? I appreciate any help!

解决方案

OpenCV is trying to tell you that one of the images you passed to cvGoodFeaturesToTrack() (the error is actually originating in the helper function cornerEigenValsVecs()) is not of the required type CV_8UC1 or CV_32FC1.

I suspect img1 may not be of the type you need it to be. What is the type of the img1 matrix? If it is color, then it may be of type CV_8UC3. Consider using cvCvtColor to make it a grayscale image.

Or, alternatively you can initially load the image as grayscale like:

cvLoadImage("im1.pgm", CV_LOAD_IMAGE_GRAYSCALE);

这篇关于OpenCV:使用函数cvGoodFeaturesToTrack时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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