OpenCV:使用函数 cvGoodFeaturesToTrack 时出错
当我调用函数 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenCV 试图告诉您,您传递给 cvGoodFeaturesToTrack() 的图像之一(错误实际上源自辅助函数cornerEigenValsVecs())不是所需的类型 CV_8UC1 或 CV_32FC1。
我怀疑 img1 可能不是您需要的类型。 img1 矩阵的类型是什么?如果是颜色,那么它的类型可能是 CV_8UC3。考虑使用 cvCvtColor 使其成为灰度图像。
或者,您也可以首先将图像加载为灰度图像,如下所示:
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: