gpt4 book ai didi

c - 尝试使用通过 cmake 安装的 OpenCV-2.3.1 在 XCode 中运行示例 MacOSX FaceTracker 程序

转载 作者:太空宇宙 更新时间:2023-11-03 22:35:03 24 4
gpt4 key购买 nike

好的。我按照本网站上的“使用 CMake 构建”指令集进行操作: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

我制作了一个“build”文件夹。我使用 cmake 生成了“Unix Makefiles”。我运行了 make -j8 和 sudo make install。一切都应该在它需要的地方,对吧?错误的。我打开 FaceTracker.xcodeproj 文件,单击“运行”,这是我得到的:

The run destination My Mac 64-bit is not valid for Running the scheme 'FaceTracker'.

The scheme 'FaceTracker' contains no buildables that can be built for the SDKs supported by > the run destination My Mac 64-bit. Make sure your targets all specify SDKs that aresupported by this version of Xcode.

我应该怎么做才能让它发挥作用?我害怕在 Lion 上使用预编译的 OpenCV 包,考虑到它们有多旧。我也是 Xcode 新手。

编辑:12 月 14 日,晚上 7:05:

我做了一个helloworld程序

////////////////////////////////////////////////////////////////////////
//
// hello-world.cpp
//
// This is a simple, introductory OpenCV program. The program reads an
// image from a file, inverts it, and displays the result.
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
IplImage* img = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;

if(argc<2){
printf("Usage: main <image-file-name>\n\7");
exit(0);
}

// load an image
img=cvLoadImage(argv[1]);
if(!img){
printf("Could not load image file: %s\n",argv[1]);
exit(0);
}

// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);

// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);

// invert the image
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

// show the image
cvShowImage("mainWin", img );

// wait for a key
cvWaitKey(0);

// release the image
cvReleaseImage(&img );
return 0;
}


我尝试用 gcc 编译它:

gcc helloworld.cpp 
helloworld.cpp:12:16: error: cv.h: No such file or directory
helloworld.cpp:13:21: error: highgui.h: No such file or directory
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:18: error: ‘IplImage’ was not declared in this scope
helloworld.cpp:18: error: ‘img’ was not declared in this scope
helloworld.cpp:20: error: ‘uchar’ was not declared in this scope
helloworld.cpp:20: error: ‘data’ was not declared in this scope
helloworld.cpp:29: error: ‘cvLoadImage’ was not declared in this scope
helloworld.cpp:40: error: expected primary-expression before ‘)’ token
helloworld.cpp:40: error: expected `;' before ‘img’
helloworld.cpp:44: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
helloworld.cpp:44: error: ‘cvNamedWindow’ was not declared in this scope
helloworld.cpp:45: error: ‘cvMoveWindow’ was not declared in this scope
helloworld.cpp:52: error: ‘cvShowImage’ was not declared in this scope
helloworld.cpp:55: error: ‘cvWaitKey’ was not declared in this scope
helloworld.cpp:58: error: ‘cvReleaseImage’ was not declared in this scope
Jesse:testing jessebikman$ g++ helloworld.cpp
helloworld.cpp:12:16: error: cv.h: No such file or directory
helloworld.cpp:13:21: error: highgui.h: No such file or directory
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:18: error: ‘IplImage’ was not declared in this scope
helloworld.cpp:18: error: ‘img’ was not declared in this scope
helloworld.cpp:20: error: ‘uchar’ was not declared in this scope
helloworld.cpp:20: error: ‘data’ was not declared in this scope
helloworld.cpp:29: error: ‘cvLoadImage’ was not declared in this scope
helloworld.cpp:40: error: expected primary-expression before ‘)’ token
helloworld.cpp:40: error: expected `;' before ‘img’
helloworld.cpp:44: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
helloworld.cpp:44: error: ‘cvNamedWindow’ was not declared in this scope
helloworld.cpp:45: error: ‘cvMoveWindow’ was not declared in this scope
helloworld.cpp:52: error: ‘cvShowImage’ was not declared in this scope
helloworld.cpp:55: error: ‘cvWaitKey’ was not declared in this scope
helloworld.cpp:58: error: ‘cvReleaseImage’ was not declared in this scope

似乎我的问题是安装的库,但考虑到我的平台不是 Linux,而是 OS X,我不确定在哪里可以找到它们,而且我没有使用 Macports 或 Home Brew,我使用了推荐安装方式,CMake。您知道我如何使用 CMake 使用的位置在我的 Mac 上设置 PKG_CONFIG_PATH 吗?安装说明非常困惑,而且我似乎无法使用CMake卸载OpenCV,这也很困惑。

最佳答案

基本上,您忘记了在 cmd 行上添加所有内容! headers 目录、libs 目录以及与适当库的链接:

g++ helloworld.cpp -o helloworld -I/usr/local/include/opencv -I/usr/local/include  -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

关于c - 尝试使用通过 cmake 安装的 OpenCV-2.3.1 在 XCode 中运行示例 MacOSX FaceTracker 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8499879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com