安装OpenCV的-2.3的Visual Studio 2010 [英] Setup OpenCV-2.3 for Visual Studio 2010
问题描述
我想使用的OpenCV 2.3和Visual Studio 2010前preSS。我的code是例如:
I'm trying to use opencv 2.3 with Visual Studio 2010 Express. My code is from example:
#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;
}
我有什么迄今所做的?
What have I done so far?
- 新增
构建\\ BIN
和构建\\有一个{86 | 64} \\ {VC9 \\ VC10 \\ MinGW的} \\ BIN
我的系统路径(使用的DLL)。 - 新增
构建\\ {86 | 64} \\ {VC9 \\ VC10 \\ MinGW的} \\ lib中
或构建\\ {86 | 64} \\ { VC9 \\ VC10 \\ MinGW的} \\ staticlib
作为图书馆目录我的连接设置。 - 新增
构建\\包含
和打造\\包括\\ OpenCV的
为包括目录,以我的编译器设置。
- Added
build\bin
and one ofbuild\{x86|x64}\{vc9\vc10\mingw}\bin
to my system path (to use DLLs). - Added
build\{x86|x64}\{vc9\vc10\mingw}\lib
orbuild\{x86|x64}\{vc9\vc10\mingw}\staticlib
as library directories to my linker settings. - Added
build\include
andbuild\include\opencv
as include directories to my compiler settings.
和结果是:
1> LINK:致命错误LNK1104:无法打开文件C:\\ OpenCV2.3 \\建立\\ 86 \\ VC10 \\ lib.obj
有没有 lib.obj
OpenCV中的文件夹。我只解压的的OpenCV-2.3.0-双赢superpack.exe
,而无需使用CMake的软件。
There's no lib.obj
in OpenCV folders. I've only unziped OpenCV-2.3.0-win-superpack.exe
, without using CMake software.
我在做什么错了?
推荐答案
那么, 官方指导 是安装的 OpenCV的2.1 在VS2010,所以我写了一些说明下面,显示了如何正确安装和配置在 86 的OpenCV 2.3 在 Visual Studio 2010中(例如preSS),因为很多人似乎有问题正确设置它。
Well, the official guide is for installing OpenCV 2.1 on VS2010, so I wrote some instructions below that shows how to properly install and configure the x86 version of OpenCV 2.3 on Visual Studio 2010 (Express), since a lot of folks seem to have problems setting it up correctly.
下载<一个href=\"http://tenet.dl.sourceforge.net/project/opencvlibrary/opencv-win/2.3/OpenCV-2.3.0-win-superpack.exe\">OpenCV-2.3.0-win-superpack.exe并执行它的所有文件解压到一个名为 OpenCV2.3
的文件夹。此文件夹中有2个目录:建立
和 OpenCV的
。所有在VS2010安装程序将参照构建
目录。出于实用的目的,我搬到文件夹 OpenCV2.3
我的 C:\\
驱动器,所以要注意路径我建议本指南为你的可能是不同的。
Download OpenCV-2.3.0-win-superpack.exe and execute it to extract all files to a folder named OpenCV2.3
. Inside this folder there are 2 directories: build
and opencv
. All the setup on VS2010 will refer to the build
directory. For practical purposes I moved the folder OpenCV2.3
to my C:\
drive, so pay attention to the paths I suggest on this guide as yours might be different.
在Visual Studio中,创建一个新的 Win32控制台应用程序任何你喜欢的项目,并为其命名。在此之后,一个新的窗口就会显示出来。点击标签上的应用程序设置并确保选择的空项目被选中:
On Visual Studio, create a new Win32 Console Application project and name it whatever you like. After that, a new window will show up. Click on the tab Application Settings and make sure the option Empty Project gets selected:
添加新文件的main.cpp
到文件夹源文件
,然后添加此code到的main.cpp
:
Add a new file main.cpp
to the folder Source Files
, then add this code to 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;
}
在这一点上,我们需要配置的项目,因此它可以找到OpenCV的头文件和库。转到项目属性( ALT + F7 ),而一旦新的窗口显示出来做到以下几点:
At this point, we need to configure the project so it can locate OpenCV headers and libraries. Go to the Project Properties (ALT+F7), and once the new window shows up do the following:
-
在配置中,选择所有配置
打开配置属性> C / C ++>常规,并编辑字段附加包含目录,以添加这些3路径(头):
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\\ OpenCV2.3 \\编译\\包括\\ OpenCV的
C:\\ OpenCV2.3 \\编译\\包括\\ opencv2
C:\\ OpenCV2.3 \\编译\\包含
注意包括\\ OpenCV的
是OpenCV中的C接口和包括\\ opencv2
如果对于C ++接口。我们也从C接口的一些头文件引用到C ++头为 opencv2被打破添加文件夹
。包含
来prevent我们的构建\\核心
Note that include\opencv
is for the C interface of OpenCV and include\opencv2
if for the C++ interface. We are also adding the folder include
to prevent our build from being broken by some headers of the C interface that refer to C++ headers as opencv2\core
.
- 然后,添加对库的路径配置属性>链接>常规,并在附加库目录字段,添加此:
C:\\ OpenCV2.3 \\建立\\ 86 \\ VC9 \\ lib中
:
- Then, add the path of the libraries on Configuration Properties > Linker > General, and on the Additional Library Directories field, add this:
C:\OpenCV2.3\build\x86\vc9\lib
:
- 最后,对于这个简单的测试,我们要添加库
opencv_core230.lib
和opencv_highgui230.lib
。所以去的配置属性>链接器>输入并添加它们:
- Finally, for this simple test we are going to add the libraries
opencv_core230.lib
andopencv_highgui230.lib
. So go to Configuration Properties > Linker > Input and add them:
在编写更复杂的应用程序,你可能会需要补充一点,我没有其他的OpenCV库
在我们这个小项目提到的。
When writing more complex applications you'll probably need to add other OpenCV libs that I did not mentioned on this little project of ours.
preSS F7 到生成解决方案的,你应该看到:
Press F7 to Build Solution and you should see:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
要能够执行则需要在应用程序的modify在 PATH系统的环境变量添加OpenCV中的DLL文件的位置。这种添加到PATH的末尾:
To be able to execute the application you'll need to modify the PATH environment variable of your system to add the location of OpenCV's DLLs. Add this to end of PATH:
; C:\OpenCV2.3\build\x86\vc9\bin
这篇关于安装OpenCV的-2.3的Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!