Vous êtes sur la page 1sur 3

Setting up OpenCV in Visual Studio 2012

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
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.
2.
Run the downloaded .exe. Select the 'Extract to' directory and press 'Extract'. (Selecting a path without
spaces is a good idea.)
3.
A folder named opencv must have been created in your selected directory. Rename it to 'opencv<yourversion-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.
1.
Create a new User Variable named 'OPENCV' and set its value to the directory where you extracted
earlier.

2.
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.
1.
Click on New Project. (Ctrl+Shift+N)
2.

Under Visual C++, choose Win32 Console Application. Give your project a name. Click on OK.

3.

A Win32 Application Wizard must have popped up. Click Next.

4.

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.
1.
If you're on a 64 bit machine, click on Build Menu and select 'Configuration Manager'.
2.

Click the combo box under 'Active solution platform' and select New

3.

In the next window, under new platform, select x64. Click OK. Close the configuration manager.

1.

Download this zip. Extract its contents to your project folder.

Part 4
2.
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.
3.

In VS, open the Property Manager window. (View Other Windows Property Manager)

4.
Click on 'Add Existing Property Sheet'. Select the OpenCV .props file(Choose 32 or 64 bit accordingly).
Click Open.

5.
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.
6.
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!

Vous aimerez peut-être aussi