OpenCV: Error when using function cvGoodFeaturesToTrack

眉间皱痕 提交于 2021-02-07 13:59:30

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/7680816/opencv-error-when-using-function-cvgoodfeaturestotrack

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