OpenGL support

OpenCV includes OpenGL support. OpenGL is a graphical library that is integrated in graphic cards as a standard. OpenGL allow us to draw from 2D to complex 3D scenes.

OpenCV includes OpenGL support due to the importance of representing 3D spaces in some tasks. To allow a window support in OpenGL, we have to set up the WINDOW_OPENGL flag when we create the window with the namedWindow call.

The following code creates a window with OpenGL support and draws a rotated plane that shows the web camera frames:

Mat frame; GLfloat angle= 0.0; GLuint texture; VideoCapture camera; int loadTexture() { if (frame.data==NULL) return -1; glGenTextures(1, &texture); glBindTexture( GL_TEXTURE_2D, texture ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); ...

Get OpenCV By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.