Elf*_*foc 36 c c++ opencv visual-studio-2010 visual-studio
我正在尝试使用Visual Studio 2010 Express的opencv 2.3.我的代码来自示例:
#include "stdafx.h"
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
int c;
// allocate memory for an image
IplImage *img;
// capture from video device #1
CvCapture* capture = cvCaptureFromCAM(1);
// create a window to display the images
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
// position the window
cvMoveWindow("mainWin", 5, 5);
while(1)
{
// retrieve the captured frame
img=cvQueryFrame(capture);
// show the image in the window
cvShowImage("mainWin", img );
// wait 10 ms for a key to be pressed
c=cvWaitKey(10);
// escape key terminates program
if(c == 27)
break;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我做了什么?
build\bin一个build\{x86|x64}\{vc9\vc10\mingw}\bin到我的系统路径(使用DLL).build\{x86|x64}\{vc9\vc10\mingw}\lib或build\{x86|x64}\{vc9\vc10\mingw}\staticlib作为库目录添加到我的链接器设置.build\include并build\include\opencv作为包含目录到我的编译器设置.结果是:
1> LINK:致命错误LNK1104:无法打开文件'c:\ OpenCV2.3\build\x86\vc10\lib.obj'
lib.obj在OpenCV文件夹中没有.我只是在OpenCV-2.3.0-win-superpack.exe没有使用CMake软件的情况下解压缩.
我究竟做错了什么?
kar*_*lip 93
那么,官方指南是在VS2010上安装OpenCV 2.1,所以我在下面写了一些说明,说明如何在Visual Studio 2010(Express)上正确安装和配置x86版本的OpenCV 2.3,因为很多人似乎都有问题正确设置.
下载OpenCV-2.3.0-win-superpack.exe并执行它以将所有文件解压缩到一个名为的文件夹OpenCV2.3.在这个文件夹里面有2个目录:build和opencv.VS2010上的所有设置都将引用该build目录.出于实际目的,我将文件夹移动OpenCV2.3到了我的C:\驱动器,因此请注意我在本指南中建议的路径,因为您可能会有所不同.
在Visual Studio上,创建一个新的Win32控制台应用程序项目,并将其命名为您喜欢的任何名称.之后,将出现一个新窗口.单击" 应用程序设置 "选项卡,确保选中" 空项目 "选项:

将新文件添加main.cpp到该文件夹Source Files,然后将此代码添加到main.cpp:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: ./opencv_hello <file.png>\n");
return -1;
}
IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!img)
{
return -1;
}
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此时,我们需要配置项目,以便它可以找到OpenCV头文件和库.转到项目属性(ALT + F7),一旦新窗口显示,请执行以下操作:
在" 配置"框中,选择" 所有配置"
打开配置属性> C/C++>常规,并编辑其他包含目录字段以添加这3个路径(对于标题):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include

请注意,这include\opencv是针对OpenCV的C接口以及include\opencv2是否适用于C++接口.我们还添加了一个文件夹,include以防止我们的构建被引用C++头的C接口的某些头部破坏opencv2\core.
C:\OpenCV2.3\build\x86\vc9\lib:
opencv_core230.lib和opencv_highgui230.lib.所以转到配置属性>链接器>输入并添加它们:
在编写更复杂的应用程序时,您可能需要添加我在我们这个小项目中未提及的其他OpenCV库.
按下F7来构建解决方案,你会看到:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
为了能够执行应用程序,您需要修改系统的PATH环境变量以添加OpenCV的DLL的位置.将其添加到PATH的末尾:
; C:\OpenCV2.3\build\x86\vc9\bin
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
65622 次 |
| 最近记录: |