OpenGL 互操作性 核心功能


名称空间

cv::ogl::ocl

class cv::ogl::Arrays
Wrapper for OpenGL Client-Side Vertex arrays. 更多...
class cv::ogl::Buffer
Smart pointer for OpenGL buffer object with reference counting. 更多...
class cv::ogl::Texture2D
Smart pointer for OpenGL 2D texture memory with reference counting. 更多...

枚举

enum cv::ogl::RenderModes {
cv::ogl::POINTS = 0x0000,
cv::ogl::LINES = 0x0001,
cv::ogl::LINE_LOOP = 0x0002,
cv::ogl::LINE_STRIP = 0x0003,
cv::ogl::TRIANGLES = 0x0004,
cv::ogl::TRIANGLE_STRIP = 0x0005,
cv::ogl::TRIANGLE_FAN = 0x0006,
cv::ogl::QUADS = 0x0007,
cv::ogl::QUAD_STRIP = 0x0008,
cv::ogl::POLYGON = 0x0009
}
render mode 更多...

函数

void cv::ogl::convertFromGLTexture2D (const Texture2D &texture, OutputArray dst)
转换 Texture2D object to OutputArray. 更多...
void cv::ogl::convertToGLTexture2D ( InputArray src, Texture2D &texture)
Converts InputArray to Texture2D 对象。 更多...
UMat cv::ogl::mapGLBuffer (const Buffer &buffer, AccessFlag accessFlags= ACCESS_READ | ACCESS_WRITE )
Maps Buffer object to process on CL side (convert to UMat ). 更多...
void cv::ogl::render (const Texture2D &tex, Rect_ < double > wndRect= Rect_ < double >(0.0, 0.0, 1.0, 1.0), Rect_ < double > texRect= Rect_ < double >(0.0, 0.0, 1.0, 1.0))
Render OpenGL texture or primitives. 更多...
void cv::ogl::render (const Arrays &arr, int mode= POINTS , Scalar color= Scalar::all (255))
void cv::ogl::render (const Arrays &arr, InputArray indices, int mode= POINTS , Scalar color= Scalar::all (255))
void cv::cuda::setGlDevice (int device=0)
Sets a CUDA device and initializes it for the current thread with OpenGL interoperability. 更多...
void cv::ogl::unmapGLBuffer ( UMat &u)
Unmaps Buffer object (releases UMat , previously mapped from Buffer ). 更多...

详细描述

This section describes OpenGL interoperability.

To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not supported). For GTK backend gtkglext-1.0 library is required.

To use OpenGL functionality you should first create OpenGL context (window or frame buffer). You can do this with namedWindow function or with other OpenGL toolkit (GLUT, for example).

枚举类型文档编制

RenderModes

#include < opencv2/core/opengl.hpp >

render mode

枚举器
POINTS
Python: cv.ogl.POINTS
LINES
Python: cv.ogl.LINES
LINE_LOOP
Python: cv.ogl.LINE_LOOP
LINE_STRIP
Python: cv.ogl.LINE_STRIP
TRIANGLES
Python: cv.ogl.TRIANGLES
TRIANGLE_STRIP
Python: cv.ogl.TRIANGLE_STRIP
TRIANGLE_FAN
Python: cv.ogl.TRIANGLE_FAN
QUADS
Python: cv.ogl.QUADS
QUAD_STRIP
Python: cv.ogl.QUAD_STRIP
POLYGON
Python: cv.ogl.POLYGON

函数文档编制

convertFromGLTexture2D()

void cv::ogl::convertFromGLTexture2D ( const Texture2D & texture ,
OutputArray dst
)

#include < opencv2/core/opengl.hpp >

转换 Texture2D object to OutputArray.

参数
texture - source Texture2D 对象。
dst - destination OutputArray.

convertToGLTexture2D()

void cv::ogl::convertToGLTexture2D ( InputArray src ,
Texture2D & texture
)

#include < opencv2/core/opengl.hpp >

Converts InputArray to Texture2D 对象。

参数
src - source InputArray.
texture - destination Texture2D 对象。

mapGLBuffer()

UMat cv::ogl::mapGLBuffer ( const Buffer & buffer ,
AccessFlag accessFlags = ACCESS_READ | ACCESS_WRITE
)

#include < opencv2/core/opengl.hpp >

Maps Buffer object to process on CL side (convert to UMat ).

Function creates CL buffer from GL one, and then constructs UMat that can be used to process buffer data with OpenCV functions. Note that in current implementation UMat constructed this way doesn't own corresponding GL buffer object, so it is the user responsibility to close down CL/GL buffers relationships by explicitly calling unmapGLBuffer() 函数。

参数
buffer - source Buffer 对象。
accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE).
返回
返回 UMat object

render() [1/3]

void cv::ogl::render ( const Texture2D & tex ,
Rect_ < double > wndRect = Rect_ < double >(0.0, 0.0, 1.0, 1.0) ,
Rect_ < double > texRect = Rect_ < double >(0.0, 0.0, 1.0, 1.0)
)

#include < opencv2/core/opengl.hpp >

Render OpenGL texture or primitives.

参数
tex Texture to draw.
wndRect Region of window, where to draw a texture (normalized coordinates).
texRect Region of texture to draw (normalized coordinates).

render() [2/3]

void cv::ogl::render ( const Arrays & arr ,
int mode = POINTS ,
Scalar color = Scalar::all (255)
)

#include < opencv2/core/opengl.hpp >

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
arr Array of privitives vertices.
mode Render mode. One of cv::ogl::RenderModes
color Color for all vertices. Will be used if arr doesn't contain color array.

render() [3/3]

void cv::ogl::render ( const Arrays & arr ,
InputArray indices ,
int mode = POINTS ,
Scalar color = Scalar::all (255)
)

#include < opencv2/core/opengl.hpp >

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
arr Array of privitives vertices.
indices Array of vertices indices (host or device memory).
mode Render mode. One of cv::ogl::RenderModes
color Color for all vertices. Will be used if arr doesn't contain color array.

setGlDevice()

void cv::cuda::setGlDevice ( int device = 0 )

#include < opencv2/core/opengl.hpp >

Sets a CUDA device and initializes it for the current thread with OpenGL interoperability.

This function should be explicitly called after OpenGL context creation and before any CUDA calls.

参数
device System index of a CUDA device starting with 0.

unmapGLBuffer()

void cv::ogl::unmapGLBuffer ( UMat & u )

#include < opencv2/core/opengl.hpp >

Unmaps Buffer object (releases UMat , previously mapped from Buffer ).

Function must be called explicitly by the user for each UMat previously constructed by the call to mapGLBuffer() 函数。

参数
u - source UMat , created by mapGLBuffer() .