Download OpenCV
The first thing to do is get OpenCV. You can download it from its sourceforge.net page. Make sure you download the latest version and the correct one for your platform.
Update: OpenCV 2.0 is now available. This post works for OpenCV 1.0. Check how to install OpenCV 2.0.
Telling your IDE about OpenCV
Once you’re done installing, you need to change some settings in your IDE so that it knows where to find the header files and the library files for OpenCV.
I’ll demonstrate the process with these IDEs: Microsoft Visual Studio 2008 and Microsoft Visual Studio 6.
Other websites mention how to use OpenCV with other environments:
OpenCV and Eclipse IDE
OpenCV and Ch
OpenCV and C++ Builder
OpenCV and DevCpp
OpenCV and Microsoft Visual Studio 2008
Start Visual Studio 2008 and goto Tools > Options.
In the Options, goto Projects and Solutions > VC++ Directories.
On this page, there is a drop down list called Show directories for. It has six options: Executable files, Include files, Reference files, Library files, Source files and Exclude directories. We’re interested in the Include files and Library files.
Select the Include files option, and setup the options as shown below:
Note: On my computer, I installed OpenCV in the D:\Program Files\OpenCV directory. You might have installed it at some different location, so make sure you change the paths appropriately.
Now change the Show directories for to Library files. All the library files of OpenCV are located in just one directory, so simply add that directory:
Note: Again, make sure you use the appropriate the directory path.
You’re done! Now your Visual Studio 6 knows where to find OpenCV!
OpenCV and Microsoft Visual Studio 6
Start Visual Studio 6.0 and goto Tools > Options.
In the Options dialog box, go to the Directories tab.
On this tab, there is a drop down list called Show directories for. It has four options: Executable files, Include files, Library files and Source files. We’re interested in the Include files and Library files.
Select the Include files option, and setup the options as shown below:
Note: On my computer, I installed OpenCV in the D:\Program Files\OpenCV directory. You might have installed it at some different location, so make sure you change the paths appropriately.
Now change the Show directories for to Library files. All the library files of OpenCV are located in just one directory, so simply add that directory:
Note: Again, make sure you use the appropriate the directory path.
You’re done! Now your Visual Studio 6 knows where to find OpenCV!
What next?
Now that your IDE knows exactly where OpenCV is, you can make OpenCV applications. To use OpenCV, you need to specify that you want to use OpenCV libraries.
You need to modify your project’s settings in order to do that. I’ll demonstrate how to do that in the next tutorial.
Next Parts
This post is a part of an article series on OpenCV for Beginners
- Why OpenCV?
- Installing and getting OpenCV running
- Hello, World! With Images!
- Filtering Images
- Capturing Images
- HighGUI: Creating Interfaces










28 Comments
hey
i got dis error while compiling in visual studio 2008 plz help me debugging it
i am just a beginner
1>—— Build started: Project: test, Configuration: Debug Win32 ——
1>Linking…
1>LINK : fatal error LNK1104: cannot open file ‘cxcore.lib’
1>Build log was saved at “file://c:\OpenCV2.0\OpenCV2.1\projects\test\test\Debug\BuildLog.htm”
1>test – 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========
Hmm.. what .lib files have you added in project options? I think it should be cxcore210d.lib or something similar
why don’t you update your tutorials to opencv v 2.1
Yup… that’s on my to-do list… thanks for reminding!
Hi! I love your site and found it very helpful. I have recently got opencv book and tried to learn on my own. As hobbyist i would like to integrate computer vision into my projects. I have been trying to run a sample program from the book and i get lots of errors. i tried to do the setup you prescribe in your tutorial. here is my program:
// opencv_helloworld.h#include "highgui.h"
int main(int argc, char** argv)
{
IplImage *img = cvLoadImage(agrv[1]);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1",img);
cvWaitKey(0);
cvDestroyWindow("Example1");
cvReleaseImage(&img);
return 0;
}
Here is is the long list II get when I Build solution maybe you can help:
1>------ Build started: Project: opencv_helloworld, Configuration: Debug Win32 ------1>Compiling...
1>opencv_helloworld.cpp
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(42) : error C2059: syntax error : 'namespace'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(43) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
[...]
1> c:\users\laptop\documents\visual studio 2008\projects\opencv_helloworld\opencv_helloworld\opencv_helloworld.h(10) : see declaration of 'opencv_helloworld::Class1'
1>c:\opencv2.1\include\opencv\cxtypes.h(418) : error C2814: 'opencv_helloworld::Class1::_IplConvKernel' : a native type cannot be nested within a managed type 'opencv_helloworld::Class1'
1> c:\users\laptop\documents\visual studio 2008\projects\opencv_helloworld\opencv_helloworld\opencv_helloworld.h(10) : see declaration of 'opencv_helloworld::Class1'
1>c:\opencv2.1\include\opencv\cxtypes.h(418) : fatal error C1003: error count exceeds 100; stopping compilation
1>Build log was saved at "file://c:\Users\laptop\Documents\Visual Studio 2008\Projects\opencv_helloworld\opencv_helloworld\Debug\BuildLog.htm"
1>opencv_helloworld - 138 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Did you include cv.h?
i came across your site during my work on virtual tour….you are doing really a great job….Thanx
Thanks! Glad you liked it!
Hi,
In version 2.2 of Open CV, when I’m changing the settings in Visual Studio to tell it where to find the OpenCV include files, would I have to add this:
C:\OpenCV2.2\include\opencv
C:\OpenCV2.2\include\opencv2\core
C:\OpenCV2.2\include\opencv2\highgui
instead of the directories you listed above for the older version of OpenCV? I’m just asking because I’m getting an error saying that:
1>c:\opencv2.2\include\opencv\cv.h(63) : fatal error C1083: Cannot open include file: ‘opencv2/core/core_c.h’: No such file or directory
even though I have included this file in my program. There might be something obvious that I’m missing?
Also, I forgot to say, I changed the dependencies in the Linker to:
cv.lib core220d.lib highgui220d.lib cvaux.lib ml220d.lib
There doesn’t seem to be anything called “cv220d.lib” or “cvaux220d.lib” so I left those as they were, but I’ve only just started using OpenCV so those may exist under different names that I don’t know yet. I’ve also copied all the dll files into C:\WINDOWS\system32. But that error still occurs.
Perhaps I need to include something else in my program in the “#include” part?
I haven’t tried version 2.2 yet, so I’m not sure. Have a look at the directories and check which ones have header files. Put all those in the Visual Studio settings. Is there a directory called “opencv2″ somewhere? Put that in the list too.
Yep, there is a directory called “opencv2″. I included it, but it still didn’t seem to work. It seems to work if I manually change all the header files to contain the full path of each header file: So something like “C:\OpenCV2.2\opencv2……..”. But I’m sure there’s a shortcut, I’ll keep trying and see.
Try adding C:\OpenCV2.2 to the include directories. That should work… I think.
I fixed this, just add C:\OpenCV2.2\include;
Hi,
The lib files that are addded as dependencies(cv.lib, highfui.lib and others) were not ther in OPenCV2.2 version lib file. So can you plz let me know the equivalent lib files to be added to VS.
You’ll have to compile OpenCV first. That will generate the .lib files. Did you do that?
A previous poster mentioned they got rid of their problem by just including OpenCV2.2\include, but in that include directory the opencv2 folder only contains one file on my machine (opencv.h).
So i don’t see how it is possible that you fixed this issue with that instruction.
I found a different solution for Cannot open include file: ‘opencv2/core/core_c.h’
I have to add C:\OpenCV-2.2.0\modules\core\include to the include directories. This is because \modules\core\include contains a folder opencv2 which has core\core_c.h ..
However after fixing this error it will give me the next error which again says cannot open opencv2/xxx/xxx.h , so I have to repeat the above include statement about 9-10 times for all the libraries e.g imgproc/highgui/ flann / features2d …
Anyone figure out a way to get by this , or understands the issue? This is the only way I can get my project to run and it is a pain in the ass.
same problem here
did you find a easy solution?
adding the 9-10 directories is too long to be the only solution!!
You need to do it once. For all future projects, you don’t need to add those directories again.
Hello,
It seems opencv is in a clumbsy transition stage between 1x and 2x. I am using Fedora 14 and my 1x version does not allow creating a VideoWriter to produce files. I believe this is because I didn’t install it with ffmpeg support or similar.
I changed course by installing FFMpeg and by using the directions from willowgarage to install the latest opencv v2.2. Now because the header and library files have changed, ffmpeg does not compile with the latest opencv headers. Here is the error when ffmped is built with “–enable-libopencv” specified:
libavfilter/vf_libopencv.c:29:28: fatal error: opencv/cxtypes.h: No such file or directory
compilation terminated.
The mere fact that the old header is being requested indicates it is also going to link to the old libraries. So much for trying to use 2.2 !!
So can I still use ffmpeg from opencv if I don’t use the –enable-libopencv option for ffmpeg?
Any help you can provide, or links you can suggest would be appreciated. As far as I am concerned, opencv is a broken piece of software if its not being used for windows or Ubuntu linux. The authors should clean things up and make more info available. I have
spent a week on this setup so far..
Thanks.
Hi Dean! I believe that the problem you’re facing is because of little details that are significantly different in Ubuntu and Fedora. For example, setting up paths for libraries in Ubuntu might be a little different from Fedora. Did you try the OpenCV Yahoo group? It has hundreds of active members and I’m sure atleast one of them has worked with OpenCV on Fedora.
Yes, you’re right about the cleaning up required. There’s way too much confusion about how to setup OpenCV on a given operating system.
Hi,
in C:\OpenCV2.2\include\opencv\cv.h file other headers files path not clear i Think.
#include “opencv2/core/core_c.h”
#include “opencv2/core/core.hpp”
whereis opencv2 ??? compiler can’t find opencv2 folder, but i apply all setting in InstallGuide, what is the correct path value for system settings.
thanks in advance
can anybody please dive me d link to download its source code…
Check the sourceforge page of OpenCV.
Thank you for the thing, I am writing a blog on openCV, while I don’t have knowledge related to installing openCV in windows.I have redirected them to you blog.And if any one visiting this blog want to know about installing openCV in linux, you can visit this link
http://opencvuser.blogspot.com/2011/06/installing-opencv.html
Thanks for sharing! Your article looks great!
Hi, Utkarsh,
I am using Visual C++ 2008 and following your installation steps to getting Open CV running. However, I am using OpenCV_b3.1 as it was THE version used for a project I am following. For the step where you were showing the include files, you had Opencv\cxcore\include. I do not have a folder call cxcore in my OpenCV. Will there be a problem there ?
I don’t think so. Have a look at the ‘include’ directory – it has everything (under different directories).