OpenCV2 Learning Notes (17): OpenCV project in VS2013 to support OpenGL __opengl

Source: Internet
Author: User
Tags win32

have been using QT+OPENCV development projects, while in VS directly lazy use precompiled OPENCV for development, resulting in the use of OpenGL prompts "No OpenGL support":

On the Internet, the reason is obvious because the precompiled library does not support OpenGL, so it is necessary to use CMake to rebuild the project. My development environment is: Win 8.1+VS2013+OPENCV 2.4.9.

Starting with the OpenCV2.4.2 version, OPENCV supports OpenGL in a visual window, and interfaces can be found in Highgui modules. This allows OPENCV to easily render any 3D content. However, OPENCV does not enable OPENGL support by default, so you need to set the flag enable_opengl=
YES, (Default Enable_opengl = NO).

After this configuration is successful, a 3D object embedding OpenGL in the display output of OPENCV will be demonstrated. The whole process is as follows:

First, generate OPENCV solution

Install CMake and open, select the OpenCV installation path after the "Browse source ..." button on the first line "where is the source code". My Opencv2.0 installation path is e:/opencv/opencv/, where I need to select the source folder, click the "Browse Build ..." button on the second line and select the path to the resulting solution. Place it in the E:/opencv/opencvbuild folder and click on the Configure at the bottom left when the setting is complete.

Select the compiler version of Visual Studio 12 (Visual Studio 2013) In the pop-up dialog box and click Finish.

In the following compile parameter settings find With_opengl, tick, click Configure again.

Click Configure again, finish clicking Generate, and close cmake. All the configuration work before this compilation is complete.

Ii. compiling OpenCV in vs

Open the OpenCV.sln under E:\opencv\OpencvBuild with VS2013. Before compiling, confirm that the solution platform is debug| Win 32. Right-click on the project All_build, select Build, Finish find Cmaketargets->install, and select Build again.

Wait for the build to complete. If the first selected solution platform chooses debug 32-bit, the solution configuration is changed to release, and then the All_build and install are waiting to be generated again, and the compilation of OpenCV is complete.

(There may be a compile error.) According to the online introduction, OpenGL in VS is supported, do not need to install, but if the compiler does not pass the situation, you can try to all use <gl\gl.h> header files before the place to add #include <windows.h>)

iii. Configuring OpenCV in VS

Here with the VS Property table Configuration OpenCV project, each time only need to add a property sheet to complete configuration, more convenient than manual interface configuration. The property manager->-> Add an existing property by right-clicking the "Test" (project name).

After you modify the name of the project's property sheet and click "Add", you can see our new property sheet (named OpenCV) in the property manager.

Right click on the property sheet we just created and click "Properties", click "VC + + catalog" in the pop-up window, click on the "Include directory" on the right side, add: E:\opencv\OpencvBuild\install\include

Similarly, in the Library directory add: E:\opencv\OpencvBuild\lib\Debug

Click the linker-> enter-> additional dependencies and add the appropriate library files as needed:

In the same way, to "release | Win32 attribute, add the property sheet to the following configuration:

Add in include directory: E:\opencv\OpencvBuild\install\include

Add in library directory: E:\opencv\OpencvBuild\lib\Release

Add to Additional dependencies: the library file under E:\opencv\OpencvBuild\install\include\Release.

After the VS complete configuration, the last step is to add the system variable Path:e:\opencv\opencvbuild\install\x86\vc12\bin;

Four, simple demonstration

All of the configuration on OpenCV and OpenGL has been completed, and the next step is to experiment with the following OPENCV to create an OpenGL window, which opens up a real-world enhancement project in the property manager debug| Win32, select Add Existing property sheet, select the previously generated OpenCV property sheet (Put the property sheet file in the project folder beforehand):

After compiling the reality enhancement project and generating the executable file, the input image can get the 3D drawing of OpenGL rendering.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.