Using OpenCV in VS2012

0. Environment

Windows 8 x64 Enterprice and Pro

Visual studio 2012

OpenCV 2.4.3 (OpenCV-2.4.3.exe)

1. Steps

1.1 Extract opencv to folder D:\GreenProgramFiles\ and your OpenCV will be installed in D:\GreenProgramFiles\opencv\, we call this folder the "OpenCV_Root_Folder"

1.2 Add "OpenCV_Root_Folder\build\x86\vc10\bin" (my folder is D:\GreenProgramFiles\opencv\build\x86\vc10\bin) to your "Path" environment variables

1.3 Create a new Win32 Console Application in C++

1.4 Right click the project and click the "Properties"

1.5 In "Configuration Properties\VC++ Directories\Include Directories", add "OpenCV_Root_Folder\build\include" (my folder is D:\GreenProgramFiles\opencv\build\include)

1.6 In "Configuration Properties\VC++ Directories\Library Directories", add "OpenCV_Root_Folder\build\x86\vc10\lib" (my folder is D:\GreenProgramFiles\opencv\build\x86\vc10\lib)

1.7 In "Configuration Properties\Linker\Input\Additional Dependencies", add the file list in "OpenCV_Root_Folder\build\x86\vc10\lib" (my folder is D:\GreenProgramFiles\opencv\build\x86\vc10\lib) which has the file name of opencv_***243d.lib for your Debug configuration and opencv_***243.lib for your Release configuration. And notice that the version number will be different if you use other version of OpenCV. My file list as following:

Debug:
opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_core243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_haartraining_engined.lib
opencv_highgui243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_photo243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_video243d.lib
opencv_videostab243d.lib

Release:
opencv_calib3d243.lib
opencv_contrib243.lib
opencv_core243.lib
opencv_features2d243.lib
opencv_flann243.lib
opencv_gpu243.lib
opencv_haartraining_engine.lib
opencv_highgui243.lib
opencv_imgproc243.lib
opencv_legacy243.lib
opencv_ml243.lib
opencv_nonfree243.lib
opencv_objdetect243.lib
opencv_photo243.lib
opencv_stitching243.lib
opencv_ts243.lib
opencv_video243.lib
opencv_videostab243.lib

1.8 Test your configuration with these code:

#include <opencv2\opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main()
{
    Mat img = imread("d:\\lena.jpg");
    if(img.empty())
    {
        cout<<"error";
        return -1;
    }
    imshow("lena test",img);
    waitKey();
    return 0;
}

2. Problems

2.1 msvcp100d.dll

If there is an error that msvcp100d.dll is needed, you may need to install VS2010 together with VS2012.

I do not know why, because one of my computer need to install vs2010, but another do not need, who can tell me why? Contact me through http://www.chenyineng.info/contact

2.2 _CrtlsValidHeapPointer error and stopped in dbgheep.c line 2036

This is because the OpenCV 2.4.3 is not compatible very well with Visual studio 2012, please try your code in Visual studio 2010

3. References

http://www.cnblogs.com/freedomshe/archive/2012/04/25/2470540.html

http://blog.sina.com.cn/s/blog_78fd98af0101a0aa.html

(This article is from http://www.cnblogs.com/chenyineng/archive/2013/01/08/2850792.html, and belongs to http://chenyineng.cnblogs.com and http://www.chenyineng.info)

posted @ 2013-01-08 11:34  Yineng  阅读(972)  评论(0编辑  收藏  举报
Homepage: www.chenyineng.info
Copyright 2010 - 2014 Yineng Chen. All rights reserved.