打开CV,Mac OS X上的图像加载问题 [英] Open CV, image loading issue on Mac OS X

查看:154
本文介绍了打开CV,Mac OS X上的图像加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的问题很基本.我试图将Open CV安装在OSX Lion上.我已按照此链接 http://tilomitra.com/opencv-on- mac-osx/

I think my question is pretty basic. I was trying to get Open CV to install on my OSX Lion. I had followed all the steps recommended on this link http://tilomitra.com/opencv-on-mac-osx/

但是,当我在Xcode上运行网站上推荐的C ++代码时,它无法使用cvLoadImage()函数加载图像.我已将图像放置在项目文件夹中(建议使用).这是我正在运行的代码:

However, when I run the C++ code recommended on the website in Xcode, it fails to load an image with the cvLoadImage( ) function. I have placed my image in the project folder (as recommended). Here is the code I was running:

// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp>

int main(int argc, char** argv)
{
IplImage * pInpImg = 0;

// Load an image from file - change this based on your image name
pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
 fprintf(stderr, "failed to load input image\n");
 return -1;
}

// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( !cvSaveImage("my_image_copy.png", pInpImg) )
{
 fprintf(stderr, "failed to write image file\n");
}

// Remember to free image memory after using it!
cvReleaseImage(&pInpImg);

return 0;
}

因此,在执行过程中,代码会成功构建,但始终会在以下循环中终止并停止执行:

So during execution, the code builds successfully, but always ends up in the following loop and halts execution:

    if(!pInpImg)
{
 fprintf(stderr, "failed to load input image\n");
 return -1;
}

以前有人遇到过这样的问题吗?我该怎么解决?

Has anyone faced such a problem before? How could I solve this?

(在安装"Macports"和"Cmake"的过程中,我收到一条警报,提示未安装Xcode或未安装命令行工具".但是,根据本论坛的另一个主题,我已经从以下位置安装了这些代码:安装Xcode时,Xcode->首选项-> Downloads文件夹. 但是,仍然在安装过程中,"Macports"和"Cmake"给了我警告,但仍然安装了.但这可能是问题吗? )

(During installation of 'Macports' and 'Cmake', I had received an alert saying that Xcode was not installed or was installed without 'Command Line Tools'. But as per another thread on this forum, I had installed these from the Xcode-->Preferences-->Downloads folder on installing Xcode. However, still during installation, 'Macports' and 'Cmake' gave me warnings, but installed anyway. But could this be the issue? )

谢谢!

推荐答案

问题是您将图像放入项目文件夹,而不是包含可执行文件的文件夹.您可以将图像文件放置在带有可执行文件的文件夹中,也可以在对cvLoadImage的调用中放置图像的完整路径.

The problem is that you're putting the image into the project folder instead of the folder containing your executable. You can either put the image file in the folder with the executable or put the full path to the image in the call to cvLoadImage.

较早版本的Xcode将可执行文件放在项目文件夹的build/Debugbuild/Release文件夹中.较新版本的Xcode将生成产品放在DerivedData文件夹的项目文件夹中.您可以通过以下方法找到DerivedData文件夹:转到文件->项目设置...,然后单击文件夹路径旁边的箭头:

Older versions of Xcode put the executable in either the build/Debug or build/Release folder in the project folder. Newer versions of Xcode put the build products in the project folder in the DerivedData folder. You can find the DerivedData folder by going to File -> Project Settings… and clicking the arrow next to the folder path:

这篇关于打开CV,Mac OS X上的图像加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆