为 Visual Studio 2010 设置 OpenCV-2.3

Setup OpenCV-2.3 for Visual Studio 2010(为 Visual Studio 2010 设置 OpenCV-2.3)
本文介绍了为 Visual Studio 2010 设置 OpenCV-2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio 2010 Express 中使用 opencv 2.3.我的代码来自示例:

#include "stdafx.h"#include int _tmain(int argc, _TCHAR* argv[]){国际 c;//为图像分配内存IplImage *img;//从视频设备 #1 捕获CvCapture* 捕获 = cvCaptureFromCAM(1);//创建一个窗口来显示图像cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);//定位窗口cvMoveWindow("mainWin", 5, 5);同时(1){//检索捕获的帧img=cvQueryFrame(捕获);//在窗口中显示图像cvShowImage("mainWin", img );//等待 10 ms 等待按键被按下c=cvWaitKey(10);//退出键终止程序如果(c == 27)休息;}返回0;}

到目前为止我做了什么?

  • buildin 和 build{x86|x64}{vc9vc10mingw}in 之一添加到我的系统路径(以使用 DLL).
  • 添加了 build{x86|x64}{vc9vc10mingw}libbuild{x86|x64}{vc9vc10mingw}staticlib 作为我的链接器设置的库目录.
  • buildincludebuildincludeopencv 作为包含目录添加到我的编译器设置中.

结果是:

<块引用>

1>链接:致命错误 LNK1104:无法打开文件 'c:OpenCV2.3uildx86vc10lib.obj'

OpenCV 文件夹中没有 lib.obj.我只解压了 OpenCV-2.3.0-win-superpack.exe,没有使用 CMake 软件.

我做错了什么?

解决方案

好吧,official guide 用于在 VS2010 上安装 OpenCV 2.1,所以我在下面写了一些说明,说明如何正确安装和配置 x86 版本OpenCV 2.3Visual Studio 2010 (Express) 上,因为很多人似乎在正确设置它时遇到问题.

下载OpenCV-2.3.0-win-superpack.exe 并执行它以将所有文件解压到名为 OpenCV2.3 的文件夹中.在这个文件夹中有 2 个目录:buildopencv.VS2010 上的所有设置都将参考 build 目录.出于实际目的,我将文件夹 OpenCV2.3 移动到了我的 C: 驱动器,因此请注意我在本指南中建议的路径,因为您的路径可能有所不同.>

在 Visual Studio 上,创建一个新的 Win32 控制台应用程序 项目并随意命名.之后,将出现一个新窗口.点击标签应用程序设置并确保选择空项目选项:

Source Files文件夹中添加一个新文件main.cpp,然后将这段代码添加到main.cpp:

#include #include #include int main(int argc, char* argv[]){如果 (argc <2){printf("用法:./opencv_hello 
");返回-1;}IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);如果(!img){返回-1;}cvNamedWindow("显示", CV_WINDOW_AUTOSIZE);cvShowImage("显示", img );cvWaitKey(0);返回0;}

此时,我们需要配置项目,以便它可以定位 OpenCV 头文件和库.转到项目属性 (ALT+F7),并在出现新窗口后执行以下操作:

  • 配置框中,选择所有配置

  • 打开 Configuration Properties > C/C++ > General,然后编辑 Additional Include Directories 字段以添加以下 3 个路径(用于标题):>

    C:OpenCV2.3uildincludeopencv

    C:OpenCV2.3uildincludeopencv2

    C:OpenCV2.3uildinclude

注意includeopencv是OpenCV的C接口,includeopencv2是C++接口.我们还添加了文件夹 include 以防止我们的构建被 C 接口的某些头文件破坏,这些头文件将 C++ 头文件称为 opencv2core.

  • 然后,在配置属性>链接器>常规上添加库的路径,并在附加库目录字段上添加:C:OpenCV2.3uildx86vc9lib:

  • 最后,对于这个简单的测试,我们将添加库 opencv_core230.libopencv_highgui230.lib.所以转到配置属性>链接器>输入并添加它们:

在编写更复杂的应用程序时,您可能需要添加其他我没有的 OpenCV 库在我们的这个小项目中提到过.

F7构建解决方案,您应该看到:

========== 构建:1 成功,0 失败,0 最新,0 跳过 ==========

为了能够执行应用程序,您需要修改系统的PATH环境变量以添加OpenCV的DLL的位置.将此添加到 PATH 的末尾:

<代码>;C:OpenCV2.3uildx86vc9in

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?

  • Added buildin and one of build{x86|x64}{vc9vc10mingw}in to my system path (to use DLLs).
  • Added build{x86|x64}{vc9vc10mingw}lib or build{x86|x64}{vc9vc10mingw}staticlib as library directories to my linker settings.
  • Added buildinclude and buildincludeopencv as include directories to my compiler settings.

And the result is:

1>LINK : fatal error LNK1104: cannot open file 'c:OpenCV2.3uildx86vc10lib.obj'

There's no lib.obj in OpenCV folders. I've only unziped OpenCV-2.3.0-win-superpack.exe, without using CMake software.

What am I doing wrong?

解决方案

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.

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.

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:

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>
");
    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;
}

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:

  • On the Configuration box, select All Configurations

  • Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):

    C:OpenCV2.3uildincludeopencv

    C:OpenCV2.3uildincludeopencv2

    C:OpenCV2.3uildinclude

Note that includeopencv is for the C interface of OpenCV and includeopencv2 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 opencv2core.

  • Then, add the path of the libraries on Configuration Properties > Linker > General, and on the Additional Library Directories field, add this: C:OpenCV2.3uildx86vc9lib:

  • Finally, for this simple test we are going to add the libraries opencv_core230.lib and opencv_highgui230.lib. So go to Configuration Properties > Linker > Input and add them:

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 to Build Solution and you should see:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

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.3uildx86vc9in

这篇关于为 Visual Studio 2010 设置 OpenCV-2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)