I had previously written a post on setting up OpenCV 2.3.1 on VS 2010. It's been long since I updated it. So here's the new post on setting up OpenCV in Visual Studio 2012.
I'll be demonstrating this with OpenCV 2.4.6 on Visual Studio 2012 Express. I assume that you've got Visual Studio 2012 already installed.
Part 1
Part 4
I'll be demonstrating this with OpenCV 2.4.6 on Visual Studio 2012 Express. I assume that you've got Visual Studio 2012 already installed.
Part 1
- Download the OpenCV installer for Windows from the official download page. Using the version just previous to the latest release is generally a good idea.
- Run the downloaded .exe. Select the 'Extract to' directory and press 'Extract'. (Selecting a path without spaces is a good idea.)
- A folder named opencv must have been created in your selected directory. Rename it to 'opencv<your-version-number>'. For ex, with OpenCV 2.4.6, I renamed it to 'opencv2.4.6'
Part 2
We need to set two environment variables. Refer this if you haven't setup environment variables before.
- Create a new User Variable named 'OPENCV' and set its value to the directory where you extracted earlier.
- Edit the variable named 'Path'. Add ";%OPENCV%\build\x64\vc11\bin" (without quotes) if you're running a 64 bit machine or ";%OPENCV%\build\x86\vc11\bin" (without quotes) if you're running a 32 bit machine. If the Path variable doesn't exist, create a new one named 'Path'.
Part 3
Start VS 2012. If it was open previously, exit it and restart.
- Click on New Project. (Ctrl+Shift+N)
- Under Visual C++, choose Win32 Console Application. Give your project a name. Click on OK.
- A Win32 Application Wizard must have popped up. Click Next.
- On the next window, make sure you tick 'Empty Project' under Additional Options. Click on Finish.
Extra Steps for 64 bit machines. If you're on a 32 bit machine, skip to Part 4.
- If you're on a 64 bit machine, click on Build Menu and select 'Configuration Manager'.
- Click the combo box under 'Active solution platform' and select New
- In the next window, under new platform, select x64. Click OK. Close the configuration manager.
- Download this zip. Extract its contents to your project folder.
- If you're using a version of OpenCV other than 2.4.6, open the OpenCV2.4.6.props file(Choose 32 or 64 bit accordingly) in a text editor. Find and Replace all '246' with your OpenCV version number. For ex, I would replace all 246 to 247 for OpenCV 2.4.7.
- In VS, open the Property Manager window. (View → Other Windows → Property Manager)
- Click on 'Add Existing Property Sheet'. Select the OpenCV .props file(Choose 32 or 64 bit accordingly). Click Open.
- In the 'Solution Explorer Window', right click on 'Source Files' folder → Add → Existing Item. Select main.cpp that you had copied to your project folder.
- Set the build target to Release. If you followed all steps correctly, hit the F5 key. The camera should fire up. Press Esc key to close the program.
If you face any problems, leave a comment. I'll try to help.
Cheers!
This comment has been removed by the author.
ReplyDeleteThank you for this. I've been looking at and trying out several ways since two days, stumbled upon this today. Of immense help.
ReplyDeleteCompiled and linked the main.cpp on VC2012.
ReplyDeleteWhen I try to run the program I get:
"The program cannot start because MSVCP120.dll is missing...".
How do I fix this?
Thanks
Peter
That dll file looks like be related to VS2012. I've not seen such an error before. You can try the steps here, maybe it solves your issue: http://stackoverflow.com/questions/19741097/missing-dll-file-when-i-run-my-application-on-another-machine
DeleteI downloaded opencv 2.4.8 from sourceforge.com and extracted it to C:\OpenCV folder. I noticed there was no bin folder in build\x86\vc11. Thus I can't set the variable path. Where can I get the bin folder and all its dll files?
ReplyDeleteDid you download the 2.4.8 file from this link http://opencv.org/downloads.html? You might have downloaded just the source archive instead of the executable.
ReplyDeleteHi Mahindra. I followed all the steps as you mentioned. But when I try to build the main.cpp It doesn't build and gives the following error:
ReplyDeleteCannot open include file: 'opencv2/highgui/highgui.hpp': No such file or directory.
Can you help me with this problem?
I have downloaded the exe file. It was of 345mb. But no bin folder and its dll files.
ReplyDeleteIt gives the error:
IntelliSense: cannot open source file "opencv2\highgui\highgui.hpp" c:\Users\Shrikant\Documents\Visual Studio 2012\Projects\opencv trial\opencv trial\Source.cpp 4 1 opencv trial
Can you tell me from where can I get the dll files?
I'm getting the following errors:
ReplyDelete1.Error 1:error LNK2001: unresolved external symbol WinMain
2.Error 2:error LNK1120: 1 unresolved externals
It work on win7 x64 and visual studio 2013 profesional. thanks!
ReplyDeleteThis comment has been removed by the author.
ReplyDeletefirst i get this error :
ReplyDelete-----
openCV_testing.obj : error LNK2019: unresolved external symbol _cvDestroyWindow
referenced in function _main
----
but i was doing this mistake :
---
active solution platform is X64 but you are trying to link x86 OpenCV libraries.
-----
Thanks
hollo, tnx for this, but I have some problems:
ReplyDelete1>LINK : fatal error LNK1104: cannot open file 'opencv_haartraining_engined.lib'
Can You help me?
THANK YOU!
ReplyDeleteopencv2/highgui/highgui.hpp
ReplyDeletethis error appears because you were supposed to extract the folder in part 1 to regular directory in my case "C:\Users\Robert\Downloads\opencv2.4.8"
Which is not the same as the location of the VS Project
I do have an error that MSVCP120.dll is missing
Will try to fix it and update y'all
so what should I do? I extract the content in C:\Users\**\Downloads\Compressed\opencv and then I copied the content only to C:\Users\**\Document\Visual Studio 2012\Project\coba but the result is same, the same error keep appearing, please help
DeleteIn order to fix the dll error install the Redistributable
ReplyDeletehttp://www.microsoft.com/en-us/download/details.aspx?id=30679
Everything works
ReplyDeleteThanks a lot!
windows 8.1
Visual Studio 2012
OpenCV 2.4.8
If you would like to choose between built in webcam and usb webcam then just change the number in the code
ReplyDeletecapture = cvCaptureFromCAM(0);
or
capture = cvCaptureFromCAM(1);
Robert: I have "opencv2/highgui/highgui.hpp" error. I reinstalled opencv-2.4.9 to C:\opencv\OpenCV2.4.9. Previously installed in C:\projects\opencv. I followed all steps above. Any suggestions? Thank you
ReplyDeleteFixed issue. Bad environment :)
ReplyDeleteHow do you fix your error? I still have the same problem as you mentioned above, but I use opencv 2.4.8 and I put the opencv folder in C:\opencv
Deletehow should I do to fix this? please help
Will this work with visual studio 2013 express in widows 8.1?
ReplyDeleteThank you for teaching opencv. I did all steps same with your vedio. But, I got error message that "Unable to start program ' C:\User\Administrator\documents\visual studio 2012\Projects\Demo\x64\Debug\Demo.exe". In the 'Debug' folder, just Demo.pdb file exist. How can I get Demo.exe? Thank you for reading my message =)
ReplyDeleteCan anyone Please help me in configuring opencv 3.0 + CUDA 6.5 + Visual Studio 2012
ReplyDeleteYou really did a great Job. I have been trying to setup Visual Studio for OpenCV for long time. I started thinking that setting OpenCV up is a myth :P
ReplyDeleteThanks