Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I was having the same problem. My mistake:

Making OpenGL calls, for example like the one you posted: cv::ogl::Texture2D texture(img);

without first having an OpenGL context current on the calling thread. Because a texture2D needs to be created within a certain encapsulated context.

The OpenGL context can constructed either through the OpenCV provided HighGUI module, using namedWindow(<window_name>, WINDOW_OPENGL), which creates a new window and corresponding OpenGL context, and sets the context of that window active (look at setOpenGLContext(..) for switches between contexts of multiple namedWindows ) .

The context can also be created through 3rd party windowing / multimedia libraries (GLUT, OpenTK, SDL, GLFW, etc.) or full blown UI toolkits (Qt, wxWidgets) (see https://www.opengl.org/wiki/Related_toolkits_and_APIs). Whichever library you use to create the context, ensure that the context is made active (the library should provide a method for this) and all subsequent calls from the ogl:: namespace should work.