Image processing in C/C++ : Installing Opencv in Microsoft Visual studio 10 ( without Cmake )
Operating System: Windows 7
For installing Visual studio 10 : http://www.microsoft.com/visualstudio/eng#products/visual-studio-express-products
(free version)
For installing Opencv-2.4.5 : http://ncu.dl.sourceforge.net/project/opencvlibrary/opencv-win/2.4.5/OpenCV-2.4.5.exe
Download the latest version of opencv and install it within
a folder say C:/program files/Opencv.
Note: Create a copy of the path variable before installing because it may replace the path variable while installing (how to get path variable is explained bellow).
Setting up path variable
Go to location where all dll files are located. Here C:\Program
Files\opencv\build\x86\vc10\bin( if your os is 64 bit then C:\Program Files\opencv\build\x64\vc10\bin).
Now Click start -> My Computer -> right click -> properties
-> Advanced System Settings -> Environment Variables -> Under system
variable select ‘path’ and click edit.
Add the location “C:\Program Files\opencv\build\x86\vc10\bin”
at the end of the path and put a semicolon at the end.
Then click Apply if not Ok.
Building a project
Open visual studio ->new project -> visual c++ -> enter name of the project(say Sample) and select
Win32 console application -> click Ok
-> click finish
In left side of the window you can see Sample. Right click Sample
-> properties -> a dialog box appears as following
Adding include and library files
Change Configuration to ‘all configuration’ ->Configuration properties -> VC++ directories
->include->edit
Ctrl-insert->browse to the location where you had
installed include files then add these locations.
Here “C:\Program Files\opencv\include\opencv” and “C:\Program
Files\opencv\include\opencv2”
Similarly add library directory
Here “ C:\Program Files\opencv\build\x86\vc10\lib “ if you are using visual studio 9 then “C:\Program
Files\opencv\build\x86\vc9\lib”
Click apply
Last Step: Go to linker -> input -> Additional
dependency ->edit then add the following files
opencv_calib3d245.lib
opencv_calib3d245d.lib
opencv_contrib245.lib
opencv_contrib245d.lib
opencv_core245.lib
opencv_core245d.lib
opencv_features2d245.lib
opencv_features2d245d.lib
opencv_flann245.lib
opencv_flann245d.lib
opencv_gpu245.lib
opencv_gpu245d.lib
opencv_haartraining_engine.lib
opencv_haartraining_engined.lib
opencv_highgui245.lib
opencv_highgui245d.lib
opencv_imgproc245.lib
opencv_imgproc245d.lib
opencv_legacy245.lib
opencv_legacy245d.lib
opencv_ml245.lib
opencv_ml245d.lib
opencv_nonfree245.lib
opencv_nonfree245d.lib
opencv_objdetect245.lib
opencv_objdetect245d.lib
opencv_photo245.lib
opencv_photo245d.lib
opencv_stitching245.lib
opencv_stitching245d.lib
opencv_superres245.lib
opencv_superres245d.lib
opencv_ts245.lib
opencv_ts245d.lib
opencv_video245.lib
opencv_video245d.lib
opencv_videostab245.lib
opencv_videostab245d.lib
These are nothing but library files in “C:\Program
Files\opencv\build\x86\vc10\lib “ ( note : never mind liblept168.lib liblept168d.lib
libtesseract302.lib in the image ).
Now copy paste the program
#include "stdafx.h"
#include<cv.h>
#include<highgui.h>
using namespace std;
using namespace cv;
int main()
{
IplImage *inputImage =
cvLoadImage( "C:/Users/Public/Pictures/Sample
Pictures/c_flight.jpg",CV_LOAD_IMAGE_COLOR);
cvShowImage("original",inputImage);
cvReleaseImage(&inputImage);
while(1)
{ }
return 0;
}
Note : Make sure #include "stdafx.h" is at
the beginning.
Now press F7 (building the project) then F5 (run the program).
That’s it !
Errors encountered during execution
E.1 Error in ‘include<cv.h>’ or any other include
files. Try ‘#include <opencv/cv.h>’.
E.2 After pressing F7 you may find errors something like ‘failed
1 success 0‘ in the output window, this is due to error in building include
or library files. This can be solved by solution of E.1 or recheck include and
library files that were done while building library
and include files.
E.3 No error during building ( F7 ) but error during
execution like ‘ linkage error ’Try adding the files
from “C:\Program Files\opencv\build\x86\vc10\lib” to project folder (here C:\...\Visual
Studio2010\Projects\Sample\Sample ).I solved the problem by adding opencv_core245.lib
opencv_imgproc245.lib opencv_highgui245.lib.