-2

我正在使用此代码来检测给定图像中的基本形状。但它说明无法打开 Image 。请帮我。如果我的问题不清楚,请告诉我

4

1 回答 1

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");
}
于 2012-12-10T06:29:57.120 回答