OpenCV:使用函数 cvGoodFeaturesToTrack 时出错

发布于 2024-12-08 17:17:12 字数 1214 浏览 3 评论 0原文

当我调用函数 cvGoodFeaturesToTrack 来查找 Harris 角时,我收到此错误:

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

它编译正确,但当我尝试运行它时,它给出了该错误。

这是代码:

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

为什么会发生这种情况以及如何修复它?我很感激任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晒暮凉 2024-12-15 17:17:12

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

我怀疑 img1 可能不是您需要的类型。 img1 矩阵的类型是什么?如果是颜色,那么它的类型可能是 CV_8UC3。考虑使用 cvCvtColor 使其成为灰度图像。

或者,您也可以首先将图像加载为灰度图像,如下所示:

cvLoadImage("im1.pgm", CV_LOAD_IMAGE_GRAYSCALE);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文