OpenCV-2.1.0 Visual C++ 2010 on Windows 7
(Verified on Windows 7 x86_64; Should also be compatible with Windows XP SP3 and newer)
This tutorial will walk the user through setup of an OpenCV project in Microsoft Visual C++ 2010 (VS 2010 Professional and Visual C++ 2010 Express ). There is a small 'Hello World' example at the end.
This guide is adapted from the Microsoft Visual C++ 2010 Express, part of MSVS 2010 Express guide.
Installation Pre-Requisites
- Microsoft Visual Studio 2010 Professional (paid) or Microsoft Visual C++ 2010 Express Edition (free).
- Note: This guide applies to both the Studio and Express Editions.
-
- Note: File listed as for VS2008, but works for 2010 as well.
OpenCV 2.1.0 HelloWorld
- (Installation Edition Dependent) Start -> All Programs -> Microsoft Visual Studio 2010 (Express) -> Microsoft Visual (Studio / C++ 2010 Express)
- File -> New -> Project
- Name: 'OpenCV_Helloworld'...'OK'...'Finish'
- Configure Project Directories
- In 2008
- Tools -> Options -> Projects and Solutions -> VC++ Directories
- In 2010
- Project -> OpenCV_Helloworld Properties...Configuration Properties -> VC++ Directories
- Include Directories... add: 'C:\OpenCV2.1\include\opencv;'
- Library Directories... add: 'C:\OpenCV2.1\lib;'
- Source Directories... add: 'C:\OpenCV2.1\src\cv; C:\OpenCV2.1\src\cvaux; C:\OpenCV2.1\src\cxcore; C:\OpenCV2.1\src\highgui; C:\OpenCV2.1\src\ml;'
- Linker -> Input -> Additional Dependencies...
- For Debug Builds.. add: 'cv210d.lib; cxcore210d.lib; highgui210d.lib;'
- For Release Builds.. add: 'cv210.lib; cxcore210.lib; highgui210.lib;'
- In 2008
- Make the content of 'OpenCV_Helloworld.cpp' as such:
// OpenCV_Helloworld.cpp : Defines the entry point for the console application. // Created for build/install tutorial, Microsoft Visual C++ 2010 Express and OpenCV 2.1.0 #include "stdafx.h" #include <cv.h> #include <cxcore.h> #include <highgui.h> int _tmain(int argc, _TCHAR* argv[]) { IplImage *img = cvLoadImage("funny-pictures-cat-goes-pew.jpg"); cvNamedWindow("Image:",1); cvShowImage("Image:",img); cvWaitKey(); cvDestroyWindow("Image:"); cvReleaseImage(&img); return 0; }
- Debug -> Build Solution
- Copy image to 'C:\Users\USERNAME\Documents\Visual Studio 2010\Projects\OpenCV_Helloworld\OpenCV_Helloworld'. Or to wherever you saved the project to...
- Debug -> Start Debugging
- Done.