Top Banner
Integrating OpenCV with Visual C++ 2008 (Windows XP) We need: 1. Microsoft Visual C++ 2008. 2. CMake You can download CMake from http://www.cmake.org/cmake/resources/software.html 3. OpenCV We will use OpenCV version 2.0, you can download it at http://sourceforge.net/projects/opencvlibrary/files/ and choose OpenCV-2.0.0a-win32.exe. Step-by-step Installation Install required software: 1. Install Visual C++ 2008. 2. Install CMake, just use default configuration, including “Do not add CMake to the system PATH” option.
14
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: procedure

Integrating OpenCV with Visual C++ 2008 (Windows XP)

We need:

1. Microsoft Visual C++ 2008.2. CMake

You can download CMake from http://www.cmake.org/cmake/resources/software.html 3. OpenCV

We will use OpenCV version 2.0, you can download it at http://sourceforge.net/projects/opencvlibrary/files/ and choose OpenCV-2.0.0a-win32.exe.

Step-by-step Installation

Install required software:

1. Install Visual C++ 2008.2. Install CMake, just use default configuration, including “Do not add CMake to the system PATH”

option.

Page 2: procedure

3. Install OpenCV library for Win32, it’s recommended to use C:\OpenCV2.0, but choose “Add OpenCV to the system PATH for all users” in install options.

After those 3 have been installed, we need to build OpenCV for Visual C++ 2008.

1. Run CMake from Start > All Programs > CMake 2.8 > CMake (cmake-gui), or from C:\Program Files\CMake 2.8\bin\cmake-gui.exe.

2. Specify “Where is the source code” as installation directory of OpenCV, i.e. C:\OpenCV2.0, and create a folder “VS2008″ (you can choose your own name) then specify “Where to build the binaries” as C:\OpenCV2.0\VS2008 for binaries output.

Page 3: procedure

3. Press “Configure” button, cmake will prompt you to specify the compiler to be used, then choose “Visual Studio 9 2008″.

Page 4: procedure

4. After click “Finish”, wait until many options are listed in red. Choose only BUILD_EXAMPLES, BUILD_PACKAGES, BUILD_TEST, INSTALL_C_EXAMPLES, OPENCV_BUILD_3RDPARTY_LIBS, and OPENCV_WHOLE_PROGRAM_OPTIMIZATION.

5. Press “Configure” and the red color will disappear.6. Press “Generate” to complete the process, then close cmake gui.

Build OpenCV binary files and configure OpenCV in Visual C++ 2008

1. Open generated Visual C++ 2008 project from previous step, which is under C:\OpenCV2.0\VS2008, by launching Visual C++ 2008 and choose File > Open > Project/Solution, then choose OpenCV.sln. Project “ALL_BUILD” will be selected.

2. Build all project using Debug configuration. After build process was finished, you will get ‘Build: 59 succeeded, 0 failed.

Page 5: procedure

3. Build all project now using Release configuration.

4. After both build, you will get 2 folder have been created under C:\OpenCV2.0\VS2008\bin, i.e. Debug folder and Release folder.

5. Now you may close the IDE. Verify that files cv200d.lib, cvaux200d.lib, etc are created under C:\OpenCV2.0\VS2008\lib\Debug; also files cv200.lib, cvaux200.lib, etc are created under C:\OpenCV2.0\VS2008\lib\Release.

6. Add those files to System Variables. 1. Right click on ‘My Computer’ then choose ‘Properties’.2. Choose ‘Advanced’ tab then click ‘Environment Variables’ button.3. Under ‘System variables’, choose ‘Path’ variable then click ‘Edit’.

Page 6: procedure

4. Append the path to OpenCV binary output, i.e. “;C:\OpenCV2.0\VS2008\lib\Debug;C:\OpenCV2.0\VS2008\lib\Release“.

5. Click OK then click OK to exit from ‘Environment Variables‘ window.

7. Open Visual C++ 2008 IDE, then select Tools > Options. In the Options window, expand Projects and Solutions then select VC++ Directories. Select Platforms as Win32, add the following path for each Show directories for.

Page 7: procedure
Page 8: procedure

8. You may add new line by pressing New Line (Ctrl-Insert) button then browse (…). Click OK to close Options windows.

9. You have completed setting up OpenCV in your Visual C++.

Page 9: procedure

Write sample program

Now is time to test OpenCV configuration by creating a sample project. This project was taken from “Learning OpenCV” book by Gary Bradski and Adrian Kaehler.

1. Create a new project by selecting File > New > Project.

2. Select Project types as Visual C++ > General, then chose Empty Project template. Specify your project Name and Location.

Page 10: procedure

3. Add new file right click on project name in Solution Explorer > Add > New Item.

4. Select Categories as Visual C++ > Code, then chose C++ File (.cpp) template. Specify your file name.

Page 11: procedure

5. Write these sample code.

6. When you try to build the project, you will get the error like these below.

7. We need additional files dependencies. Right click on project then choose Properties. Select Configuration Properties > Linker > Input. Add the following files into Additional Dependencies; you may need to click browse (…) then enter the file name, use ENTER and no COMMA in between.

cv200.libcvaux200.libhighgui200.libcxcore200.libml200.libopencv_ffmpeg200.libcxts200.lib

Page 12: procedure

8. Click Apply and OK. Rebuild the project, you should get no error

9. Use the Run button on the IDE to run the program.