xcode 打开简历,Mac OS X 上的图片加载问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12766091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open CV, image loading issue on Mac OS X
提问by yashc
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/
我认为我的问题很基本。我试图让 Open CV 安装在我的 OSX Lion 上。我已按照此链接http://tilomitra.com/opencv-on-mac-osx/上推荐的所有步骤进行操作
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:
但是,当我在 Xcode 中运行网站上推荐的 C++ 代码时,它无法使用 cvLoadImage() 函数加载图像。我已将我的图像放在项目文件夹中(如推荐)。这是我正在运行的代码:
// 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?
有没有人遇到过这样的问题?我怎么能解决这个问题?
(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? )
(在安装“Macports”和“Cmake”的过程中,我收到了一条警告,说 Xcode 没有安装或安装时没有使用“命令行工具”。但根据本论坛上的另一个帖子,我已经从 Xcode 安装了这些 - -> 首选项--> 安装 Xcode 时的下载文件夹。但是,仍然在安装过程中,“Macports”和“Cmake”给了我警告,但还是安装了。但这可能是问题吗?)
Thank you!
谢谢!
回答by SSteve
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
.
问题是您将图像放入项目文件夹而不是包含可执行文件的文件夹中。您可以将图像文件放在可执行文件所在的文件夹中,也可以将图像的完整路径放在对cvLoadImage
.
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:
旧版本的 Xcode 将可执行文件放在项目文件夹中的build/Debug
或build/Release
文件夹中。较新版本的 Xcode 将构建产品放在 DerivedData 文件夹中的项目文件夹中。您可以通过转到 File -> Project Settings... 并单击文件夹路径旁边的箭头来找到 DerivedData 文件夹:
回答by Bella
In the project folders, go to 'Products' > right click on the executable file > 'Show in Finder' > put the input image there. The output image ('.png' file) will go here as well.
在项目文件夹中,转到“产品”> 右键单击可执行文件>“在 Finder 中显示”> 将输入图像放在那里。输出图像('.png' 文件)也将放在这里。