我在 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;
}
有人知道发生了什么吗?任何帮助,将不胜感激!