Win7 安装 OpenCV2.3.1 到VS2010

Getting Started with OpenCV 2.3.1 in Microsoft Visual Studio 2010 in Windows 7 64-bit


I was trying to install OpenCV 2.3.1 on my Windows 7 64-bit machine and i kept getting the error: The application was unable to start correctly (0xc000007b)

I tried chasing the problem down using freely available program Dependency Walker and it looked like my executable project was x86 whereas all the dll files it was loading up were x64. So after many tries including re-building OpenCV using CMake, changing dll links to x86, etc., i finally figured out how to solve this problem, which i have presented as a tutorial below.

This tutorial assumes that you have installed Microsoft Visual Studio 2010 Professional.  If you are a student you can get it for free athttps://www.dreamspark.com/Products/Product.aspx?ProductId=25.

This tutorial contains the following:

  • How to download and install the OpenCV library
  • How to manually change the system path to include the bin file
  • How to create a project
  • How to configure Visual Studio to use OpenCV
  • A sample program that displays a video from a camera

Downloading and Installing OpenCV

OpenCV is a computer vision library written mainly in C that focuses on real time video processing.  It is open source or free to the public.

  1. Go to http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/
  2. Select the OpenCV-2.3.1-win-superpack.exe file and download it.
  3. Go the folder where you downloaded the executable file in Step 2 and select “Run as Administrator”.
  4. The executable file is essentially an archive of files with an extractor built in. It will ask you to select the location where you would like it to extract all its contents. Select: C:\Program Files\ as the path and click Extract. It will create a folder called OpenCV2.3.1 with the path: C:\Program Files\OpenCV2.3.1

Manually Changing the System Path to Include the Bin File

  1. To access the system path in Vista go to Control Panel\System and Security\System and on the left hand side selectAdvanced system settings this should bring up the Systems Properties dialogue.  Click on theAdvanced tab and then the Environment Variables button.
  2. This will bring up the Environment Variables dialogue.  In the System Variables box selectPathand then Edit
  3. When modifying the path know that it is sensitive to all characters including spaces.  To add the new bin, type a semicolon directly after the text that is there without adding in a space.  Next add the path to the bin file.  The path is the same as where you chose to install OpenCV back in step 4 of Downloading and Installing OpenCVsection plus \bin. For example if you chose to install OpenCV in:

    C:\Program Files\OpenCV2.3.1

    For 64 bit Windows, add the following to the system path:

    ;C:\Program Files\OpenCV2.3.1\build\bin\;C:\Program Files\OpenCV2.3.1\build\x64\vc10\bin\

    Make sure to restart your computer so the changes can take effect.

Creating a Project

  1. Click FileNewProject
  2. In the “Installed Templates”  box choose Visual C++Win32
  3. On the right choose Win32 Console Application
  4. Enter a name for the project and click OK
  5. Click finish in the dialogue box which appears

Configuring Visual Studio

  1. Click ProjectProperties to access the properties dialog
  2. In the left box click on Configuration Properties and on the top right click onConfiguration Manager

  3. In the Configuration Manager dialog box that opens up, under Active Solution Platformcombo box selectNew.
  4. In the New Solution Platform dialog box that opens up, under Type or select the new platform, selectx64,copy settings from Win32 and make sure that Create new project platformsis selected. ClickOK.
  5. You will notice that the in the Configuration Manager dialog box x64 platform has now been selected. Click Close.
  6. In the left box choose Configuration Properties C++ General
  7. In the right box, next to Additional Include Directories type the following text:
    C:\Program Files\OpenCV2.3.1\build\include;C:\Program Files\OpenCV2.3.1\build\include\opencv;%(AdditionalIncludeDirectories)

    IMPORTANT note that all these paths assume that you installed in the default location, if you installed in a different location; for example Program Files (x86) instead of Program Files, make sure you change these paths to reflect that.

  8. Next in the felt box choose Configuration Properties → Linker → Input
  9. In the right box, next to Additional Dependencies type the following text:
    "C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_core231d.lib";"C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_highgui231d.lib";"C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_video231d.lib";"C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_ml231d.lib";"C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_legacy231d.lib";"C:\Program Files\OpenCV2.3.1\build\x64\vc10\lib\opencv_imgproc231d.lib";%(AdditionalDependencies)
  10. IMPORTANT note that all these paths assume that you installed in the default location, if you installed in a different location; for example Program Files (x86) instead of Program Files, make sure you change these paths to reflect that.

  11. Click Apply then OK

Sample Program

This program will capture video from a camera and display it.  Press escape to stop capturing and displaying frames.

It may be necessary to change the number in this line of code to select the camera source:

1CvCapture* capture = cvCaptureFromCAM(1);// capture from video device #1

If you do not know the video device number just try 0, then 1,  2 or else -1. Copy and paste the following code:

01#include "stdafx.h"
02#include <highgui.h>
03 
04int _tmain(intargc, _TCHAR* argv[])
05{
06    intc;
07    // allocate memory for an image
08    IplImage *img;
09    // capture from video device #1
10    CvCapture* capture = cvCaptureFromCAM(1);
11    // create a window to display the images
12    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
13    // position the window
14    cvMoveWindow("mainWin", 5, 5);
15    while(1)
16    {
17        // retrieve the captured frame
18        img=cvQueryFrame(capture);
19        // show the image in the window
20        cvShowImage("mainWin", img );
21        // wait 10 ms for a key to be pressed
22        c=cvWaitKey(10);
23        // escape key terminates program
24        if(c == 27)
25        break;
26    }
27 return0;
28}

If when you debugging the program, “Cannot find or open the PDB file” appears, try:

1.Open property page of the current project.

2 Choose "chracter set", change it to "Use multi-byte chracter set".


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值