HOWTO Setup OpenCV
From RFC Cambridge Wiki
|Revision as of 03:42, 2 February 2006
RShi (Talk | contribs)
â† Previous diff
|Revision as of 03:43, 2 February 2006
RShi (Talk | contribs)
OpenCV with DevCPP
Next diff â†’
|Line 23:||Line 23:|
|==OpenCV with DevCPP==||==OpenCV with DevCPP==|
|-||OpenCV is Intelâ€™s open source computer vision library. It contains a huge collection of computer-vision related algorithms, data structures, filters, etc. that we may find useful.||+||OpenCV is Intel's open source computer vision library. It contains a huge collection of computer-vision related algorithms, data structures, filters, etc. that we may find useful.|
|Once your IDE is set up, go to http://sourceforge.net/projects/opencvlibrary/ and click on the opencv-win link||Once your IDE is set up, go to http://sourceforge.net/projects/opencvlibrary/ and click on the opencv-win link|
Revision as of 03:43, 2 February 2006
Setting up OpenCV in a variety of environments.
OpenCV with V2005
The follwing instructions are for setting up OpenCV inside Win XP/2000 using the Visual Studio 2005 environment.
Obtain the executable source files (available in the files section) and install OpenCV.
Make sure the path to the OpenCV libaries are correctly set (should be the check box during installation.)
- You can set this yourself if you move the directory by right clicking My Computer and selecting properties (or hitting Win Key + Break), selecting the Advanced Tab, and hitting the Environment Variables button on the bottom. In User Variables, there should be a PATH setting, set to where the OpenCV library is installed (default is C:/Program Files/OpenCV/bin).
Open the Visual Studio 2005 environment, and open the opencv.sln solution file stored in the _make directory of your installation. (default is C:/Program Files/OpenCV/_make).
- This should load the entire solution into the Visual Studio environment.
In Visual Studio, select the build file-menu, and select Build Solution.
- Optional: You make choose to clean the solution before building.
- Note: It takes a significant amount of time to compile the entire OpenCV library.
Enjoy your newly built OpenCV library!
OpenCV with DevCPP
OpenCV is Intel's open source computer vision library. It contains a huge collection of computer-vision related algorithms, data structures, filters, etc. that we may find useful.
Once your IDE is set up, go to http://sourceforge.net/projects/opencvlibrary/ and click on the opencv-win link
Click on the Download OpenCV Beta5 link. On the next page, choose a mirror to download
Run the setup program you just downloaded. Accept all the defaults; this will install OpenCV to C:/Program Files/OpenCV.
If you navigate to the C:/Program Files/OpenCV/samples/c directory, you will find a bunch of C/C++ code samples, showing off some of OpenCVâ€™s capabilities. Some of them require a connected webcam to work; those wonâ€™t do anything if you open them up. You can see some examples of edge detection, erode/dilation, etc.
IMPORTANT: There is a naming problem with the latest beta5 version of openCV. Navigate to the C:/Program Files/OpenCV/bin directory. There you will find several .dll files with an 097 in them. Copy each .dll, and change the name from 097 to 096. (i.e., the copy of cv097.dll becomes cv096.dll, same for cvaux, cvcam, cxcore, and highgui) (this can be done by running copy *097.dll *096.dll under the command shell)
Add the C:/Program Files/OpenCV/bin directory and the C:/Program Files/OpenCV/otherlibs/highgui directory to your system PATH variable. This tells the computer where to find the .dll system libraries. To do this, go to Start Menu->Control Panel -> System (or hit the Windows Button + break keys). Go to the Advanced tab and click the Environmental Variables button. In the lower box, find the variable labeled PATH. Click Edit. In the lower text box, navigate to the end and append ;C:/Program Files/OpenCV/bin;C:/Program Files/OpenCV/otherlibs/highgui (remember the semicolons). Click OK in all the windows.
Open up Bloodshed Dev-C++
Go to File->Open Project or Fileâ€¦ and open up C:/Program Files/OpenCV/samples/c/contours.c
Make a new file (File->New->Source File). Copy and paste the code from contours.c into this new file, and save it as test.cpp
Go to Tools->Compiler Options. It should come up with the Compiler tab selected. Check the box labeled Add these commands to the
linker command line and type (or copy-paste) the following into the text box:
-lhighgui -lcv -lcxcore -lcvaux -lcvcam
This tells the IDE to link your program with the OpenCV libraries.
Switch to the Directories tab, and in the Libraries sub-tab add to directories:
Switch to the C includes tab. Add
C:/Program Files/OpenCV/cxcore/include C:/Program Files/OpenCV/cv/include C:/Program Files/OpenCV/otherlibs/highgui C:/Program Files/OpenCV/cvaux/include C:/Program Files/OpenCV/otherlibs/cvcam/include as include directories.
Do the same thing for the C++ includes tab.
Now you should be able to compile and run the test.cpp sample file with the command Execute->Compile and Run. This program analyzes the image of the faces to extract information about the different regions. You can change the level of the contour to see different elements of the face (eyes, pupil, nose, mouth, etc). Play around with the source code for this program; change parameters or a line of code, and see what it does. Make sure to recompile with (Execute->Compile and Run) every time you make a change.
OpenCV with G++ (on a linux system)
If you use linux, you can set up opencv there with g++ by following these steps:
Go to http://sourceforge.net/projects/opencvlibrary/ and download the opencv-0.9.7.tar.gz file. (Note version might change later)
As superuser, Go to the directory you downloaded the tar.gz file into. There, type
tar -xzf opencv-0.9.7.tar.gz cd opencv-0.9.7 ./configure && make && make install
Opencv should be installed. But we need to prepare g++ to work with opencv. So, go to your home directory and open the .bashrc file. Append the following to the file.
alias gcv="g++ -I/usr/local/include/opencv -lcv -lcxcore -lcvaux -lhighgui"
Now, go to the opencv-0.9.7 directory from earlier, into samples, and into c, and make sure the following runs the contour program.
gcv coutours.c && ./a.out
If not, troubleshoot. If so, you should be good.