Using OpenCV 2.4.2 with Visual Studio 2012 on Windows 7 (64-bit)

EDIT: I have not updated this article since Nov 21, 2012. There might have been a lot of changes since then. If anyone is interested in updating it, shoot me a mail and I’ll give you the editing rights to this article.


So before starting you’ll need to make sure you have these in your computer:

  1. Visual Studio 2012 (You can download the 90-day trial version from here)
  2. OpenCV 2.4.2 (You can download it from here)

Extract OpenCV in a folder named OpenCV-2.4.2 in C drive. [Note: You can change the path and folder name but then you wont be able to use the instructions as they are and you'll have to make modifications]

There are five simple steps that we have to make sure that we follow to get OpenCV up and running smoothly: (Click on the images to enlarge them)

Step-1

Add the path to OpenCV runtime dll’s (Dynamic Linked Libraries) to your Environment Path variable:

[For 64-bit Machines]   C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin;C:\OpenCV-2.4.2\opencv\build\common\tbb\intel64\vc10;
[For 32-bit Machines]   C:\OpenCV-2.4.2\opencv\build\x86\vc10\bin;C:\OpenCV-2.4.2\opencv\build\common\tbb\ia32\vc10;    

The first path[C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin] is for OpenCV runtime dll’s and the second path[C:\OpenCV-2.4.2\opencv\build\common\tbb\intel64\vc10] adds Intel Threaded Building Blocks to enable parallel code in OpenCV. Adding Intel TBB dll’s is OPTIONAL. Without it you won’t be able to use multiple cores unless you multithreaded your own application.

Step-2

Create a new Visual Studio Project. Open Visual Studio -> New Project -> Visual C++ -> Win32 Console Application. Click OK. Then click Next -> Finish. 

Step-3

[This step is for people with 64-bit machines. People with 32-bit machines can skip it.] Now change the build configuration by going to Build menu -> Configuration Manager.

Change the Platform. Click on Win32, Select New. Use the settings as shown in the figure.

Step 3

Step 3

Click OK. Close the Configuration Manager. Change the configuration in the main window to Release, if it isnt that already.

Step-4

Now we add the OpenCV libraries to our OpenCV project properties. Go to View -> Other Windows -> Property Manager. Then open the Release | x64 (32-bit users should open Release | Win32) Property page by double clicking on it:

Step-4

Go to Linker -> General -> Additional Library Directories. Add this path over there:

[For 64-bit Machines]   C:\OpenCV-2.4.2\opencv\build\x64\vc10\lib;   

[For 32-bit Machines]   C:\OpenCV-2.4.2\opencv\build\x86\vc10\lib;

Next, go to Linker -> Input -> Additional Dependencies. 

Step-4i

Add the following dependencies to it:

opencv_core242.lib
opencv_imgproc242.lib
opencv_highgui242.lib
opencv_ml242.lib
opencv_video242.lib
opencv_features2d242.lib
opencv_calib3d242.lib
opencv_objdetect242.lib
opencv_contrib242.lib
opencv_legacy242.lib
opencv_flann242.lib

Step-5

Now we add the OpenCV include directories to our OpenCV project properties. In the same Property page, go to C/C++ -> General -> Additional Include Directories and add the following path:

[For both 32-bit and 64-bit Machines]   C:\OpenCV-2.4.2\opencv\build\include\opencv;C:\OpenCV-2.4.2\opencv\build\include;

[Optional: Go to C/C++ -> Preprocessor -> Preprocessor Definitions and add this: _CRT_SECURE_NO_WARNINGS; Helps avoid unnecessary warnings sometimes]

OKAY! So now we are done with the adjustments. Go ahead and try this simple code which displays the video stream from your webcam.


#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"

/**
* @function main
*/
int main( int argc, const char** argv )
{
CvCapture* capture;
IplImage* frame = 0;

while (true)
{
//Read the video stream
capture = cvCaptureFromCAM(1);
frame = cvQueryFrame( capture );

// create a window to display detected faces
cvNamedWindow("Sample Program", CV_WINDOW_AUTOSIZE);

// display face detections
cvShowImage("Sample Program", frame);

int c = cvWaitKey(10);
if( (char)c == 27 ) { exit(0); }

}

// clean up and release resources
cvReleaseImage(&frame);

return 0;

}

Once you get this basic sample up and running, you can try out other Visual Studio projects like face-detection and face-extraction I’ve put up on github.

Post your feedback or any problems that you encounter in comments.

Some blog posts that helped me figure stuff out:

1. http://jepsonsblog.blogspot.in/2012/07/installation-guide-opencv-24-with.html

2. http://siddhantahuja.wordpress.com/2011/07/18/getting-started-with-opencv-2-3-in-microsoft-visual-studio-2010-in-windows-7-64-bit/

click tracking

About these ads

158 thoughts on “Using OpenCV 2.4.2 with Visual Studio 2012 on Windows 7 (64-bit)

  1. Anders says:

    Thanks for a great guide! Small error that bugged me for a while: You must put a final ‘\’ at the system path-variables

    [For 64-bit Machines] C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin;C:\OpenCV-2.4.2\opencv\build\common\tbb\intel64\vc10\;
    [For 32-bit Machines] C:\OpenCV-2.4.2\opencv\build\x86\vc10\bin;C:\OpenCV-2.4.2\opencv\build\common\tbb\ia32\vc10\;

    • Hi Anders,

      Thanks! I just checked it out on my system with and without the ‘\’ and they both work alright. What error exactly did you get when there was no ‘\’ in your path variable?

  2. Anders says:

    Runtime: “The program can´t start because opencv_highgui242.dll is missing from your computer. Try reinstalling the program to fix this problem.”

    • That is pretty strange. Was adding that ‘\’ the only change you made before the program started executing without the error you mention? Are you running in Release Configuration? I suggest that if your program executes correctly now, then you remove the ‘\’ from the path variable and check again. I am guessing you made some other changes apart from adding that ‘\’ which got the code working. Other than that, I cannot think of anything else. Let me know.

      • Anders says:

        Youre right!! Strange. Did the following:

        1.Compiled without any changes -Runtime error.
        2. Copied opencv_highgui242.dll to my project folder (x64/release/) – no errors
        3. Deleted opencv_highgui242.dll in project folder and changed Path variable with a extra ‘\’ – no errors
        And now, changed Path back (without \) and everything works fine… Strange!

  3. Kushal Prasad says:

    Great work Karan! Cheers to you bro :) I had given up on cmake and was about to give up on this. You did such a great job of giving instructions which were easy to follow and it worked! by the way, works with other versions of opencv by just renaming the library dependencies eg. opencv_core242.lib to opencv_core243.lib if you have OpenCV 2.4.3.
    Thanks a lot bhai!

    Trying to work on hand gesture(pose) recognition using Kinect. Any help would be great… I am using only the depth feed and trying to count the number of digits held up as well as add a few mathematical operators recognition eg.two fingers crossing is ‘plus’ or ‘multiplied by’ or something like that. Haven’t had any experience working with OpenCV and I am kind of lost on how to approach the problem specially working on ‘two’ hands.

    Anyway, Cheers mate! Keep up the good work. Been of great help.
    Hope to see more of your projects soon.

    • I was also going to give up. Then I realized that I could get it working without using CMake by using the pre-built libraries. So I searched around and found some tutorials and that helped to get it working. And, yeah it should work with about any version of OpenCV. I am glad it was of any help!

      Unfortunately, my knowledge of OpenCV is as limited as yours is, perhaps even less. So I am afraid I wont be of any help. But I am pretty sure I have read somewhere about using Kinect, OpenNI to identify individual fingers. Perhaps, you could use fiducial markers on each finger to identify the number of fingers. Then based on the orientation of those markers with respect to each other you could decide which mathematical operator to assign to each. Ofcourse this is just a crude idea based on something I read about Tracking Colored Objects in OpenCV. But for this to work, you’ll need Color Data feed from Kinect.

  4. Unhandled exception at at 0x7576B9BC in openCV.exe: Microsoft C++ exception: cv::Exception at memory location 0x002FF970.

    i always got this error when i try to run the program, i already followed the intruction you got there but it seems the error is somewhat memory related and it freaks me out because we are currently working on our thesis using opencv..we tried it to other laptop too and got the same error after running it for about 3 mins or more..

    please help us, thank you in advance.

    • Hi Felix,

      Are you running the code using OpenCV 2.4.2 with Visual Studio 2012 on Win 7 64-bit? If I could know your system configuration I could try to reproduce that error and see what went wrong.

      • Sina says:

        I have Win 7 x64 with Visual Studio 2012 and OpenCV2.4.5 and I have the same problem. Before this I had VS 2010 and everything was ok (I know the settings) but I needed ImageWatch so I had to install VS2010

      • Sina says:

        Sorry I needed to install Visual Studio 2012 and I forgot to mention that this happens when I try to use calibration and similar codes from OpenCV templates. I used _CRT_SECURE_NO_WARNINGS to prevent debug error on localtime function (VS proposed using localtime_S)

  5. Muhammad Awais says:

    bro i run the code its compile successfully bt at execution time ths error occure
    “the application was unable to strt correctly(0xc0000007b) click ok to close this application” y ths happen

  6. hani says:

    Hi Mr. Karan.

    Im kinda new to opencv programming but i heard its the best for vision algorithms. Im using algorithms for colour based detection of an object (moving or stationary). My main trouble is selecting the region of interest (to be detected in consequent frames). Is there any way i can use a mouse to select my object/region on the image frame? Is there another way than mouse callback for user to access pixels?
    Your feedback frm you will be highly appreciated

  7. maryam says:

    look karan i hope that you can help me on my project ,it is very simple all i have to do is to count tha number of black squares and the number of white squares in an image using c++

  8. deven says:

    i get Runtime: “The program can´t start because opencv_highgui242.dll is missing from your computer. Try reinstalling the program to fix this problem.” like anders, i have tried removing adding / but nothing works..i am doing it on visual studio 2012 ultimate and open cv 2.4.3 …in path variable i see …common/tbb/ doesnt exist in my open cv 2.4.3 pls..help me soon…

  9. Senta says:

    Hi I have 64 bit machine, and i got openCV working in release configuration / x64.
    However is there away to get openCV running in debug mode?
    Since debugging doesn’t work properly in release mode.

    do you just replace the dependencies
    opencv_core242.lib with opencv_core242d.lib
    I saw this in the OpenCV2 cook book ?

    Thanks for the tutorial btw

  10. Dewan says:

    hello

    my system configuration is : windows xp 64 bit + visual studio 2012 + opencv 2.4.3 . Can you please tell me ? how i can start with ?

  11. Jack says:

    hello,
    I have a lil problem which stop me doing anything else. After following your instruction I run the code u posted. And here the system responded to me: The Program cant start because opencv_highgui242.dll is missing from your computer. Try reinstalling the program to fix the problem

    I found this file in C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin—- so that it could be a problem in changing the Environment Path variable, again I re-did it but there was nothing changed.
    Hope you can help me out.

  12. deven says:

    If you have 2.4.3 opencv then

    C:\OpenCV-2.4.2\opencv\build\common\tbb\intel64\vc10;
    for 2.4.3 open cv we don’t have to include this in path
    rest procedure is same as blog
    C/C++ -> Preprocessor -> Preprocessor Definitions and add this: _CRT_SECURE_NO_WARNING this will remove certain errors
    and in every dll file replace 242 with 243 .
    copy dll files (from vc10/bin)where your executable program is….if bin, is not detected in path variable…

  13. Ben says:

    Karan, gonna use your advice on compiling opencv for msvstudio 2012 for win7. Was thinking of changing to 2010 express edition because it was causing headaches for others when installing. Don’t know if you are aware but coursera.org are running free courses for computer vision, alongside many other courses. Let you know whether my install is working. Cheers!

  14. It worked out!! Thanks a lot.
    I have tried these same steps in Windows 8 and perfectly works too.
    The only trouble I had is the first step “STEP:1 Add the path to OpenCV runtime dll’s (Dynamic Linked Libraries) to your Environment Path variable” which gave me trouble with a .dll runtime error.
    Make sure you add the “OpenCV runtime dll’s” to the PATH variable.
    Thanks again!!

  15. Soumyajit says:

    I am getting all theese errors.. :( What could be the problem? i am on win7 64bit and VS2010 ultimate.

    ‘testCV.exe': Loaded ‘C:\Users\Payne\Documents\Visual Studio 2010\Projects\testCV\x64\Release\testCV.exe’, Symbols loaded.
    ‘testCV.exe': Loaded ‘C:\Windows\System32\ntdll.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\kernel32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\KernelBase.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Users\Payne\Documents\Visual Studio 2010\Projects\testCV\x64\Release\opencv_highgui243.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\user32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\gdi32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\lpk.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\usp10.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msvcrt.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\ole32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\rpcrt4.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\oleaut32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\advapi32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\sechost.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Users\Payne\Documents\Visual Studio 2010\Projects\testCV\x64\Release\opencv_core243.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msvcp100.dll’, Symbols loaded.
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msvcr100.dll’, Symbols loaded.
    ‘testCV.exe': Loaded ‘C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16385_none_a44af8ec57f961cf\comctl32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\avifil32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\winmm.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msacm32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msvfw32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\shell32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\shlwapi.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\avicap32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\version.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\imm32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\msctf.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Users\Payne\Documents\Visual Studio 2010\Projects\testCV\x64\Release\opencv_ffmpeg243_64.dll’, Binary was not built with debug information.
    ‘testCV.exe': Loaded ‘C:\Windows\System32\ws2_32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\nsi.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\wsock32.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\cryptbase.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\uxtheme.dll’, Cannot find or open the PDB file
    ‘testCV.exe': Loaded ‘C:\Windows\System32\dwmapi.dll’, Cannot find or open the PDB file
    The thread ‘Win64 Thread’ (0xfc8) has exited with code -1073741510 (0xc000013a).
    The program ‘[6072] testCV.exe: Native’ has exited with code -1073741510 (0xc000013a).

    • Soumyajit says:

      I tried both the with ‘\’ and without ‘\’ in Path and all the files are copied to my .exe folder (otherwise other problems came up). Still these errors i mentioned above remain!

  16. Thank you so much for this extremely helpful tutorial. Using this I was able to get things up and running smoothly. Oddly enough, although I’m on 64-bit windows I had to use the 32-bit instructions to get anything to work. Anyway, thank you again for such a detailed walkthrough!

  17. manhnguyen says:

    thank you so much, i feel very interesting with ‘helloworld’ example. I just install opencv2.4.3, it actives very good. thank………..

  18. sameer says:

    Hey Karan,
    I set everything up as you instructed and it seems to work fine.
    When i open a new .cpp file or a new project it doesn’t allow me to build or debug it..
    Also do i need to go through the 5 steps mentioned above for each new project i create or is there some way to save the settings for all of them ??
    And how do i give command line arguments ?

    Thanks in advance :)

    • Hi Sameer,

      If you go to the github links at the end of the tutorial, you’ll find that I’ve provided a property sheet (.props) file. If you include that, then theres no need to go through all these steps.

  19. prashastha says:

    ‘opencv_wbcm.exe’ (Win32): Loaded ‘C:\Users\vasistha\Documents\Visual Studio 2012\Projects\opencv_wbcm\x64\Release\opencv_wbcm.exe’. Symbols loaded.
    ‘opencv_wbcm.exe’ (Win32): Loaded ‘C:\Windows\System32\ntdll.dll’. Cannot find or open the PDB file.
    ‘opencv_wbcm.exe’ (Win32): Loaded ‘C:\Windows\System32\kernel32.dll’. Cannot find or open the PDB file.
    ‘opencv_wbcm.exe’ (Win32): Loaded ‘C:\Windows\System32\KernelBase.dll’. Cannot find or open the PDB file.
    ‘opencv_wbcm.exe’ (Win32): Loaded ‘C:\Users\vasistha\Documents\Visual Studio 2012\Projects\opencv_wbcm\x64\Release\opencv_highgui242.dll’. Cannot find or open the PDB file.
    ‘opencv_wbcm.exe’ (Win32): Unloaded ‘C:\Users\vasistha\Documents\Visual Studio 2012\Projects\opencv_wbcm\x64\Release\opencv_highgui242.dll’
    The program ‘[3416] opencv_wbcm.exe’ has exited with code -1073741701 (0xc000007b).

    I am getting these errors while running the project. What can i do to remove these errors ??

      • Sam says:

        Hi to anyone still struggling with this problem.
        I had this problem and tried to add path to system variables and it did not work.
        However, I added a PATH with value : (your opencv dir)\build\x86\vc10\bin
        to the USER VARIABLES and it works for me. NOT SYSTEM VARIABLES, but USER VARIABLES.

  20. kpcamota says:

    Thanks for this tutorial. I follow this and made all things working on my Windows 8 64bit and 2.4.3 version of OpenCV

    but I also had a problem with “opencv_highgui243.dll is missing from your computer”. So what I did is copy the all the dll files from opencv and paste it to the project folder (x64\release) and everything works fine.

    but its a bit annoying, why is my path variable isn’t working? I believe i made it correctly.

    Any help is appreciated :)

  21. koko says:

    I follow ur guide everything but i got an error
    can u help me please?
    [img]http://www.uppic.org/thumb-EE04_513CEF97.jpg[/img]

    Thank you so much

  22. Vinicius Vicente says:

    I got a problem with environment path as well. I had to copy ALL dll’s to my projetc’s folder to make it work. I don’t know why my computer isn’t getting the values in path variable.. :(

  23. Amith says:

    hi, Codes are compiling but when i try to run the program i am getting this following error
    opencv_highgui242.dll is missing

    • Mohammad says:

      I found the answer.
      I download opencv 2.4.5 from the official site and do all the instruction on it and get opencv_highgui242.dll error.
      then use cmake and create the install folder and compile it .
      It work correctly. :D

  24. Pema says:

    I am using OpenCV 2.4.4 and using in Visual C++ 2010 and my system is wind0w 7 64 bits … i followed your instruction but is giving following errors… can u help me Please…

    1>—— Build started: Project: Webccam, Configuration: Release Win32 ——
    1> Webccam.cpp
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvCreateCameraCapture
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvQueryFrame
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvGetCaptureProperty
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvNamedWindow
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvCreateVideoWriter
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvWriteFrame
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvShowImage
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvWaitKey
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvReleaseVideoWriter
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvReleaseCapture
    1>Webccam.obj : error LNK2001: unresolved external symbol _cvDestroyWindow
    1>c:\users\user\documents\visual studio 2010\Projects\Webccam\Release\Webccam.exe : fatal error LNK1120: 11 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  25. Andrews_12 says:

    Great Instructions!!!
    Thanks a lot!

    But i have a problem with my pc…
    When i am building any code this messages appears :

    The program can´t start because tbb.dll is missing from your computer..

    Any ideas?

  26. rana says:

    hello, good work.. but i am having this error “Error 1 error C2061: syntax error : identifier ‘OutputArray’ “

  27. HI Karan and community!
    I have my opencv – Visual Studio 2012 environment working fine.
    But I still have a problem:
    When I open a new project, I MUST set again the opencv tunes in project properties, I mean, putting the dlls and directories in the project properties dialog.
    In the last visual Studio 2010, was easy, just opening an existing project properties file, but I cannot find the same in this release …
    Could anyone help me?
    Thanx in advance.

    Javier,.

    • Hey Javier,

      If you check the github page for any of the projects linked, you’ll see that I’ve provided an OpenCV.props file. You can include that in your properties explorer menu and all the dependencies will automatically be added to the project. Similarly you can create your own .props file.

  28. Hi Karan,
    I’m using VS2012 on Windows 8. I tried configuring for OpenCV 2.4.5. But when I build, I get a linking error.

    error LNK1104: cannot open file ‘opencv_calib3d245d.lib’

    I’m pretty sure I followed the steps and configured necessary paths everywhere.
    Why do you think this happens?

  29. Wildthing says:

    At the first step why did you use C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin rather than C:\OpenCV-2.4.2\opencv\build\x64\vc11\bin ?

  30. Nouman says:

    Hi, I did all the settings according to the above tutorial and at the end when i test the code, I got following 2 errors and 1 warning

    Warning 1 warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.

    Error 2 error C1083: Cannot open include file: ‘SDKDDKVer.h': No such file or directory

    3 IntelliSense: cannot open source file “SDKDDKVer.h”

    Kindly help me guyz. Thnaks

  31. Matze says:

    Hey.
    I have following error:
    error LNK1181: input file “opencv_core242.lib” cannot open. c:\Users\Matze\documents\visual studio 2012\Projects\Win32Project2\Win32Project2\LINK Win32Project2

    Can u help me, please?
    Where is my mistake? :-(

    Thank You

  32. Saurabh Patel says:

    Can you help me to setup openCV with Qt Creator on ubuntu 12.10? I tried and run Face recognization program but the program can’t open my webcam.

  33. Emad says:

    Thanks bro! You can’t imagine how helpful your guidance was. I was frustrated about getting it run. it is working now , incredible !!

  34. icedfusion says:

    Is there a way to access other video streams and not just the USB camera? i.e. can I use a usb video capture device and still access the video stream using the CvCaptureFromCAM procedure?

  35. souvik says:

    Hey Karan,

    Awesome work with your blog. Thank you for reducing those plethora of required/un-required information into just 4 small steps.
    BTW I ran into the same problem as ANDERS where the highgui242.dll was kept reported missing. I think the problem is that VS ’12 does not register the change in the environment path variable unless you restart it(and I dont mean a rebuild, I mean the entire damn s/w). So basically I had to close VS and restart so it registers the new path variable. I had first put the 32-bit path so VS kept reporting that error even after changing the path variable. Restarted VS and I could see my face on the screen! :D

  36. aso says:

    I am new in this field of programming; and I have the problem as most of them mentioned before can’t find highgui242.dll or is missing….
    Please help

  37. chinmay says:

    1>—— Build started: Project: ConsoleApplication1, Configuration: Release Win32 ——
    1> ConsoleApplication1.cpp
    1>ConsoleApplication1.cpp(5): fatal error C1083: Cannot open include file: ‘opencv/highgui/highgui.hpp': No such file or directory
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Thisis problem oferror in build when i execute above code
    pls help to resolve it.

  38. Jashanvir Singh says:

    hello karan i got an error
    “Error 1 error LNK1181: cannot open input file ‘opencv_core242.lib’ ”
    please help me out…

  39. Nicolai Skovhus says:

    First of all, thanks for the guide – I DID indeed make your code work (though I have no webcam, I’m assuming the fact that the .exe ran without errors means it worked?). However, my question is:
    Now I need to do several projects using openCV for my codes to work. I just did ALL these steps, and copy/pasted the given code in, just to check. This is done and over, project is saved and I open a new project. ALL the settings for openCV is now gone (I guess?). At least the given code won’t work when I open a new project, unless I go through all of the steps again.
    TLDR: How do I quickly implement this openCV library into new visual studio projects?

    Win7 64-bit
    OpenCV 2.4.2
    Visual Studio 2012

    • Hi Nicolai,

      You can create a custom property sheet containing all your customizations i.e. build paths, libraries, etc. or you can just use the property sheet provided here: OpenCV Property Sheet . Note that this property sheet is for the version of OpenCV used in the tutorial above. You might have to change the version and/or the path of the OpenCV libraries(in case you did not use the path in the tutorial).

      Hope that helps. Cheers!

      • Hello Karan,

        I got following errors when I tried to run your given program.

        1>—— Build started: Project: ConsoleApplication1, Configuration: Release x64 ——
        1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(344,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.
        1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(249,5): error : Required file “tracker.exe” is missing.
        ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

        My system is of 64-bit and i have followed every steps properly.
        So help me to sort this out.
        Actually I am new to opencv and visual studio.

  40. SRIRAM says:

    awesome tutorial but i don’t know why it didn’t work for me :(
    i am too a beginners just learning .
    i am curious to know how to use the samples provided .
    i am using vs2010 and opencv 2.3 and 2.4.5 both .
    can you please guide me .
    i tried to do that on ubuntu it worked fine , but can you please tell how to use in windows

  41. Kartik says:

    Do i need to follow all the steps for every new project?..and if there is any quicker way….can you explain in detail….
    Thankyou…

  42. Daniel Devlin says:

    I am getting an error Link: fatal error LNK1181: cannot open input file ‘opencv_calib3d245.obj’
    I am using 2.4.5 opencv package for this.

    Thanks in advance.

  43. Jesus says:

    Hi I tried to install it but it lauch the next error “error C1083: Cannot open include file: ‘stdafx.h': No such file or directory” I don’t know why, someone who knows please help me.

    • Entopy117 says:

      when you open a new project if you remember you have to go through a set up page from a start up page, on the next page right after you set up the project name don’t tick “Empty Project” insteay choose “Pre compiled header” stdafx.h” is a standard generated for your library by VS so it will be included automatically right at the start up.

      Cheers.

  44. Entopy117 says:

    “Adding Intel TBB dll’s is OPTIONAL.” ? And then you carry on that …. Without it you won’t be able to use multiple cores unless… is it OPTIONAL Then?

  45. Tseno says:

    Error 2 error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\main.obj Tracker
    Error 1 error LNK2019: unresolved external symbol _cvShowImage referenced in function _main C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\main.obj Tracker
    Error 5 error LNK2019: unresolved external symbol _cvReleaseCapture referenced in function _main C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\main.obj Tracker
    Error 4 error LNK2019: unresolved external symbol _cvQueryFrame referenced in function _main C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\main.obj Tracker
    Error 3 error LNK2019: unresolved external symbol _cvCreateCameraCapture referenced in function _main C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\main.obj Tracker
    Error 6 error LNK1120: 5 unresolved externals C:\Users\Hulk\documents\visual studio 2012\Projects\Tracker\Debug\Tracker.exe Tracker

    This is my problem, help !

  46. Jan says:

    First of all thank you for this tutorial. But i have a strange problem with the cascade classifier.
    He won t load any of the haarcascades. Alway returning erros and i don t know any solution. Tried nearly anything.

    Here what the compiler says:
    Unhandled exception at at 0x000007FEFD40940D in BasisOpenCv.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000001AED00.

    Thank you for your help.

  47. USG says:

    i got a error message called …………………………….. when I trying to compiling it
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvReleaseIm
    age referenced in function _main
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvNamedWind
    ow referenced in function _main
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvShowImage
    referenced in function _main
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvWaitKey r
    eferenced in function _main
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvCreateCam
    eraCapture referenced in function _main
    ConsoleApplication3.obj : error LNK2019: unresolved external symbol _cvQueryFram
    e referenced in function _main
    ConsoleApplication3.exe : fatal error LNK1120: 6 unresolved externals

    plzzzzzzzzzz help me

  48. Hello

    First thanks for this information but i still have troubles with running the application, when i run it always pop up an error an don compile the code it says “Unable to start program”, Could you help me?

    Thanks again and have a good day.

  49. hi karan,
    thank a lot dude, u have saved my life… even i was having lots of library link error before but later your tutorial and ur faqs solved my problem.. thank u once again… since i am very new to opencv, can u suggest me some good tutorial sites to learn opencv from the basics??

  50. Fady says:

    I followed all the directions to the letter.
    My program runs but doesn’t show anything on the “sample” program screen.
    I’m using VS 2012 and OpenCV 2.4.7.
    Any ideas?
    Thank you in advance.

    • Fady says:

      Nevermind!
      I found my error. :)
      I was using
      “capture = cvCaptureFromCAM(1);”
      instead of
      “capture = cvCaptureFromCAM(0);”.

      Thanks a lot for the info.

  51. Hello Karan,

    I got following errors when I tried to run your given program.

    1>—— Build started: Project: ConsoleApplication1, Configuration: Release x64 ——
    1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(344,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.
    1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(249,5): error : Required file “tracker.exe” is missing.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    My system is of 64-bit and i have followed every steps properly.
    So help me to sort this out.
    Actually I am new to opencv and visual studio.

  52. samith says:

    Please tell me How I can Fix this problem

    I use VS2012 OpenCV 2.4.8 & Windows8 64bit Os

    I have error like this:

    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Users\Samith\Documents\Visual Studio 2012\Projects\FaceDetection3\x64\Release\FaceDetection3.exe’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\ntdll.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Program Files\AVAST Software\Avast\snxhk64.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\kernel32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\KernelBase.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_core248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_imgproc248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_highgui248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_features2d248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_calib3d248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msvcp110.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msvcr110.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\user32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\gdi32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\ole32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\oleaut32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\advapi32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\comctl32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msvfw32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\avifil32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\avicap32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\OpenCV\opencv2.4.8\build\x64\vc11\bin\opencv_flann248.dll’. Cannot find or open the PDB file.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\combase.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msvcrt.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\rpcrt4.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\sechost.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\winmm.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\shell32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msacm32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\version.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\winmmbase.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\shlwapi.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\imm32.dll’. Symbols loaded.
    ‘FaceDetection3.exe’ (Win32): Loaded ‘C:\Windows\System32\msctf.dll’. Symbols loaded.
    The program ‘[2344] FaceDetection3.exe’ has exited with code -1 (0xffffffff).

    How I fix this?

  53. Raghunandan b says:

    hi, after the setup of open cv 2.4.8 in MS visual studio 2012 , if i run a code it is giving an error, MSVCP120D.dll is missing from your computer, how to overcome this error, please help me in this regard

  54. Peter says:

    Thanks so much! I was going crazy on this until I found your very well written Tutorial.
    You are really helping the beginners. Hope I can give something back to the comunity some day.

    Cheers
    Peter

    PS: What does v10 stand for in the path C:\OpenCV-2.4.2\opencv\build\x64\vc10\bin in Step1. I’ve seen there is v11 and v12 in my build too.

  55. Hey! Thanks for the tutorial. I was able to successfully integrate openCV with VIsual Studio. I needed to ask however that whether the process needs to be repeated everytime we create a new project for OpenCV?

    • Hi Ayush,

      No. You don’t need to repeat the process everytime. If you follow the link at the bottom of the article, you’ll find a custom property sheet has been provided. You can make a similar property sheet for your project using the steps shown in the post. Then you can use that sheet in every project without having to follow all the steps.

      Hope this helps!

  56. pikeee says:

    I’m using VS2012 with OpenCV2.4.8 in W8. Pretty cool its work.

    So the steps are still same right if I’m using the code for face detection u gave. just copy + paste the code. is it?

  57. Hi Karan. Thanks for such great works. I am working on a project named virtual dressing rooms. I have considered it like static images for each size of shirt or paint and then sowing it on demand. but i think this is very childish approach. Here I found that you have also done this. Please help me in overall concept of how this is possible. please

  58. Pi_Co says:

    So I am a little confused about the enviroment path varible stuff. I know of Start->System->Advanced->path but do i really need to go that deep or is it something to add to visual?

    • Pi_Co says:

      Disregard that last message but mabye i am missing something crutial lol. How/where do I enter that sample code. (I have never used visual before and this IDE is pretty complex)

  59. unhandle memory exception error while cpmpiling in vs 2010 for opencv 2.4.9. i got error in IplImage* img=cvCreateImage(cvGetSize(frame),frame->depth,1);
    please give me the solution for this…

  60. Andrew says:

    Thank you very much for this tutorial! Followed it step by step with OpenCV 249 and VS 2012 but whenever I try to run the code, I get the following error in the Command Box:

    “…visual studio\projects\ConsoleApplication1\x64\release\ConsoleApplication1.exe” is not recognized as an internal or external command, operable program or batch file. Press any key to continue…

    Any idea where I may have gone wrong? Much appreciated!

Comments anyone? Huh? huh? huh?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s