我正在使用此code来检测给定图像中的基本形状。但它告诉我们无法打开图像。请帮我。如果我的问题不明确,请告诉我
答案 0 :(得分:2)
您的问题需要更多详细信息才能获得有效答案(例如,您是在Macintosh或iPhone上执行此操作)。
您指向失败的示例中的代码是:
img=cvLoadImage("shape.jpg");
if(img==NULL)
{
printf("Error in opening image\n");
return -1;
}
您需要将文件放在应用找到的位置。
如果您使用的是Macintosh,请将文件放在实际二进制可执行文件所在的位置(例如“MyApp.app/Contents/MacOS/MyApp
”)。或者将路径更改为您知道图像已保存的精确位置(例如“/tmp/shape.jpg
”或“/Users/sri/shape.jpg
”)。
已编辑以添加针对iOS的操作。试着这样做:
NSString *str = [[NSBundle mainBundle] pathForResource:@"YQpBE" ofType:@"png"];
if(str)
{
const char *pathToFile = [str UTF8String];
img=cvLoadImage(pathToFile);
if(img==NULL)
{
NSLog( @"could not open image file at path %@", str);
}
} else {
NSLog( @"could not find a file named YQpBE.png in the resource folder of this app");
}