1

我在 Mac 上将以下代码与 OpenCV 一起使用。以下函数从另一个函数接收图像文件的路径,并且工作正常。但是,cvExtractSURF 会抛出一个异常,说明:

OpenCV 错误:cvCreateSeq 中输入数组 () 的大小不正确,文件 >/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarb>alls_ports_graphics_opencv/opencv/work/OpenCV-2.4.1/modules/core/src/ datastructs.cpp,第 372 行终止称为抛出异常

代码如下:

- (int)extractFromImagePath:(NSString*)pathToFile{
[self.statusText setStringValue:@"image received"];
NSLog(@"Path: %@",pathToFile);
// Path: /Users/loco/Desktop/testimage.png

const char * path = [pathToFile UTF8String];
IplImage* image = cvLoadImage(path, CV_LOAD_IMAGE_GRAYSCALE );
cv::Mat im = cv::imread(path,0);
if(im.data == NULL) 
{
    std::cout<<"Unable to read "<<path<<std::endl;
    return 0;
}    

/* extract the SURF keypoints/descriptors of an image */
// presumes a previously declared IplImage *image
CvSeq *keypoints = NULL;
CvSeq *descriptors = NULL;
CvMemStorage *storage = cvCreateMemStorage(0);
cvExtractSURF(image, NULL, &keypoints, &descriptors, storage, cvSURFParams(0, 600));
// OpenCV Error: Incorrect size of input array () in cvCreateSeq, file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/OpenCV-2.4.1/modules/core/src/datastructs.cpp, line 372
// terminate called throwing an exception


[self.statusText setStringValue:@"writing to files"];

/* build a path to save a file in the documents directoy */
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString *xmlpath_kp = [docs stringByAppendingPathComponent:@"keypoints.xml"];
NSString *xmlpath_desc = [docs stringByAppendingPathComponent:@"descriptors.xml"];

/* serialize to xml and save to disc */
cvSave([xmlpath_kp UTF8String], keypoints);
cvSave([xmlpath_desc UTF8String], descriptors);

[self.statusText setStringValue:@"done"];
/* don't forget your cleanup ;) */
cvReleaseImage(&image);
cvClearMemStorage(storage);
return 1;
}

有人知道发生了什么吗?任何帮助,将不胜感激!

4

3 回答 3

1

我测试了你的部分代码抛出错误。以下代码没有给出任何错误,只需检查一下。

IplImage* image = cvLoadImage("C:\\Koala.jpg",CV_LOAD_IMAGE_GRAYSCALE);
CvSeq* kp_pns;
CvSeq* desct;
CvSURFParams pams;
pams.hessianThreshold=10;
pams.nOctaveLayers=4;
pams.nOctaves=3;
pams.upright = true;
CvMemStorage *storage = cvCreateMemStorage(0);
cvExtractSURF(image,NULL,&kp_pns,&desct,storage,pams,0);

我能够毫无错误地提取冲浪关键点。我希望错误会得到解决。

于 2012-07-03T20:13:19.303 回答
0

调整 SURF 的 hessianThreshold;他们说来自OpenCV;

hessianThreshold仅提取 hessian 大于该值的特征。好的默认值是~300-500(可能取决于图像的平均局部对比度和清晰度)。用户可以根据其 hessian 值和其他特征进一步过滤掉一些特征。

于 2012-07-30T07:24:47.193 回答
0

正如 Andrey Kamaev 指出的,这是 2.4.0 和 2.4.1 中的一个错误。升级确实解决了它。

于 2012-07-30T12:11:02.390 回答