This post is a Pictographic representation about how to integrate Visual C++ and OpenCV..This post would help you Integrate any Visual C++ version with OpenCV.
A step by step procedure is given regarding how to integrate the Visual C++ with the OpenCV..
Now having posted some programs in Dev C++ IDE let us switch to
the microsoft Visual C++ and in this post I will speak about how to integrate the Microsoft 6.0 version with Opencv…So lets see…after installing the Visual C++….here we will follow sourceforge.net with some slight modifications.So lets do it….If someone wants a direct link to sourceforge here is the link..
http://opencvlibrary.sourceforge.net/VisualC%2B%2B
So sourceforge.net says:
Linking DLLs:
- To permanatly include necessary dll files, add
C:\Program Files\OpenCV\bin
to PATH by visiting Advanced tab in System of Windows (the locate of directory might be different). - One can just copy necessary dll files into project directory with source files.
- It might be required to restart Visual C++ when execution of instance failes after successful build.
(In many instances even without setting the path ..if you copy the dll files in your project directory ..would suffice but still since sourceforge asks us to do so.. it would be a good practice to do so and you may not choose to follow my words.)
Look at the Figure Below.

- So to follow the first step, right click on the “My Computer” and click on “Properties” and then click on the advanced tab.Now you see the Environment Variables Highlighted.
Click on the same.You will see a window like the adjacent figure(Except the arrow mark).Now you see an arrow mark in the adjacent figure indicating “path” which is the variable name.Now click the same path and click “Edit”(“Edit” which is nearer to path and not the “Edit” which is below) and in the variable value paste this path
C:\Program Files\OpenCV\bin
and click on “OK” and once again click “OK” until the window “System Properties” window disappears.
path-before-changing

Copy paste the OpenCV path
- Now Second step asks us to copy the .dll files into the folder where we are working.So lets do it.
- Third Step asks us to start Visual C++ and it is tested in VC++ 2003…So lets test and find out what to do in VC++ 6.0.
So the next steps in sourceforge.net are
Customize Global Options:
- Open the Visual C++ .Net Application. In the menu bar, select Tools->Options
- In the listing, choose Projects->VC++ Directories.
- First, select Library files from the “Show Directories for” List Box.
- Click the Insert New icon, and locate the folder where you have installed opencv.
- Consider that it is installed in
C:\Program Files\OpenCV
- In the Library files list, locate and add the code below:You can find library files list in the next figure where it shows “Include Files”.In the same drop down list you would find library files(in the figure below).
C:\Program Files\OpenCV\lib
- So the first step would be correct but you would not get the window
as shown and it is given here for you convinience.
You can just blindly copy and paste whatever
shows in the figure.The paths to copy are:C:\Program Files\OpenCV\cvinclude C:\Program Files\OpenCV\cxcore\include C:\Program Files\OpenCV\otherlibs\highgui C:\Program Files\OpenCV\cvaux\include C:\Program Files\OpenCV\otherlibs\cvcam\include
- These are the paths to be copied and make sure that you have copied and pasted them with the correct drop down options being Win32 and Include files.

Now lets see what source forge says :
Next, choose source files in the list box, and locate and add the following directories:
-
C:Program Files\OpenCV\cvsrc C:\Program Files\OpenCV\cxcore\src C:\Program Files\OpenCV\cvaux\src C:\Program Files\OpenCV\otherlibs\highgui C:\Program Files\OpenCV\otherlibs\cvcam\src\windows
So again the concept is the same but the window would be different.
The inlcude files are the same, the window is the same as the above one..but you just need to chose the Source files option from the Drop Down list.Again you may blindly copy and paste the paths by following the figure and provided you have adhered to the correct option in the drop down list which is the Source files.

source-files1
Now since you are done with this window just click “OK” for VC++ to accept the changes.
Now lets follow the next step of source forge
Create New Project:
- Within Developer Studio create new application:
- Select from menu “File”->”New…”->”Projects” tab
- Choose “Win32 Application” or “Win32 console application” - the latter is the easier variant and both the sample projects have this type.
So here again just the window is only different everything else is the same

- You may Choose “Win32 Console Application” and then type the name of the project and click “ok” and you are done.click on ok and you should get this window.
After you click on finish you should be getting another window which says that no files would be added to the project just click “finish”.

Now source forge says
- After the above steps done Developer Studio will create the project folder (by default it has the same name as the project), .vcproj file, Solution .sln and, Three Source files: .cpp, stdafx.cpp and stdafx.h. StdAfx files are precompiled header files, which can be very useful if you want to reduce the compilation time.
- For example, consider that we have created a new “Hello” Project. Open the Hello.cpp file, and include the OpenCV-related #include directives:
#include "cv.h" #include "cxcore.h" #include "highgui.h"
- Note that these should be included after stdafx.h or you may get build errors.
- Now Type some OpenCV code, and Build the Solution by pressing the F7 Key. There should be linker errors.
You may copy and paste this code:
I have copied this code from one of the forums for you because it is a very simple code which does not cause more confusion.If you are not able to understand the code please study some of my very basic posts after you configure your Visual C++.
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
int main ()
{
/* new IplImage structure 'img', using 8-bit unsigned integer representation
over 3 channels. This constructs a colour image with blue, green and red
channels (in that order) with each colour value being an 8-bit unsigned
integer (0-255).*/
IplImage *img = cvCreateImage(cvSize(320, 240), IPL_DEPTH_8U, 3);
/* fill every third channel (all the red ones) with value 255.*/
register int i;
for (i = 0; i < (img -> imageSize); i+=3)
img ->imageData[i] = 255;
for(i=1;i < (img -> imageSize);i+=3)
img-> imageData[i]=250;
for(i=2;i < (img -> imageSize);i+=3)
img->imageData[i]=110;
/* a visualization window is created with title 'image'*/
cvNamedWindow ("image", 1);
/*img is shown in 'image' window*/
cvShowImage ("image", img);
cvSaveImage("image4.jpg",img);
/*wait for infinite delay for a keypress*/
cvWaitKey ();
/*memory release for img before exiting the application*/
cvReleaseImage (&img);
/*Self-explanatory*/
cvDestroyWindow("image");
return (0);
}
sourceforge says the next steps would be…
- Add dependency projects into workspace.
- Choose from menu: “Project” -> “Properties“.
- Choose “Linker” tab -> “Input” category -> “Additional Dependencies:”. Add the paths to all neccessary import libraries (cxcore[d].lib cv[d].lib highgui[d].lib cvaux[d].lib cvcam[d].lib)
- Now lets see the steps what source forge tells us to do..
So according to sourceforge if we interpret the first step for VC++6.0 then it would be
Go to “Projects” and then click on “Settings”
then you will find a window which would be something like this
So click on the “Link” tab and then follow the next figure.

In this figure go to the end of the line which is indicated by the arrows and type this or yoy may copy and paste this:
cv.lib cxcore.lib highgui.lib

and ensure the spaces after every word and “OK” everything.
But If you are using the express 2008 edition after doing all this you need to go to this page.
You are ready to Enjoy Computer Vision.

do u have ne code which implements stauffer grimson paper “adaptive background mixture models for real time tracking”…if yes…plzzzzzzzzzzzz send d links to them…
i need it very badly…
Comment by happy — May 22, 2009 @ 9:04 am |
Right now I have no means by which I get access to papers …so If you have the paper or any explanation of the same you may send it to my Email:colouredpages@gmail.com
Comment by colouredpages — May 25, 2009 @ 3:45 am |
can you send me link to download software?
for OpernCV and another support software.
detect_sy@yahoo.co.id
Comment by Inzar — August 26, 2009 @ 6:50 pm |
Hey,
first of all it is free and you can find it on the sourceforge…and then what is the support software you are speaking about..?
Regards,
Abhijeet.
Comment by colouredpages — August 27, 2009 @ 9:20 pm |
Great job and, in general, interesting posts! It’s also attractive to speak about the integration with qt4. In my spare time trying to develop a program with stereovision and qt4 opengl. Visit http://blog.roccoagostino.eu/2011/09/22/stereovisione-con-opencv/ (languaeg is italian but you can traslate). I wait your comments about my job. Thanks for your posts!
Comment by rocky — November 21, 2011 @ 6:07 am |