opencv on mbed
OpenGL interoperability
[Core functionality]
This section describes OpenGL interoperability. More...
Data Structures | |
class | Buffer |
Smart pointer for OpenGL buffer object with reference counting. More... | |
class | Texture2D |
Smart pointer for OpenGL 2D texture memory with reference counting. More... | |
class | Arrays |
Wrapper for OpenGL Client-Side Vertex arrays. More... | |
Enumerations | |
enum | RenderModes |
render mode More... | |
Functions | |
Buffer () | |
The constructors. | |
Buffer (int arows, int acols, int atype, unsigned int abufId, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Buffer (Size asize, int atype, unsigned int abufId, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Buffer (int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Buffer (Size asize, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Buffer (InputArray arr, Target target=ARRAY_BUFFER, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | create (int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false) |
Allocates memory for ogl::Buffer object. | |
void | create (Size asize, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | release () |
Decrements the reference counter and destroys the buffer object if needed. | |
void | setAutoRelease (bool flag) |
Sets auto release mode. | |
void | copyFrom (InputArray arr, Target target=ARRAY_BUFFER, bool autoRelease=false) |
Copies from host/device memory to OpenGL buffer. | |
void | copyFrom (InputArray arr, cuda::Stream &stream, Target target=ARRAY_BUFFER, bool autoRelease=false) |
void | copyTo (OutputArray arr) const |
Copies from OpenGL buffer to host/device memory or another OpenGL buffer object. | |
void | copyTo (OutputArray arr, cuda::Stream &stream) const |
Buffer | clone (Target target=ARRAY_BUFFER, bool autoRelease=false) const |
Creates a full copy of the buffer object and the underlying data. | |
void | bind (Target target) const |
Binds OpenGL buffer to the specified buffer binding point. | |
static void | unbind (Target target) |
Unbind any buffers from the specified binding point. | |
Mat | mapHost (Access access) |
Maps OpenGL buffer to host memory. | |
void | unmapHost () |
Unmaps OpenGL buffer. | |
cuda::GpuMat | mapDevice () |
map to device memory (blocking) | |
cuda::GpuMat | mapDevice (cuda::Stream &stream) |
Maps OpenGL buffer to CUDA device memory. | |
void | unmapDevice (cuda::Stream &stream) |
Unmaps OpenGL buffer. | |
unsigned int | bufId () const |
get OpenGL opject id | |
Texture2D () | |
The constructors. | |
Texture2D (int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease=false) | |
Texture2D (Size asize, Format aformat, unsigned int atexId, bool autoRelease=false) | |
Texture2D (int arows, int acols, Format aformat, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Texture2D (Size asize, Format aformat, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Texture2D (InputArray arr, bool autoRelease=false) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | create (int arows, int acols, Format aformat, bool autoRelease=false) |
Allocates memory for ogl::Texture2D object. | |
void | create (Size asize, Format aformat, bool autoRelease=false) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | release () |
Decrements the reference counter and destroys the texture object if needed. | |
void | setAutoRelease (bool flag) |
Sets auto release mode. | |
void | copyFrom (InputArray arr, bool autoRelease=false) |
Copies from host/device memory to OpenGL texture. | |
void | copyTo (OutputArray arr, int ddepth=CV_32F, bool autoRelease=false) const |
Copies from OpenGL texture to host/device memory or another OpenGL texture object. | |
void | bind () const |
Binds texture to current active texture unit for GL_TEXTURE_2D target. | |
unsigned int | texId () const |
get OpenGL opject id | |
void | setVertexArray (InputArray vertex) |
Sets an array of vertex coordinates. | |
void | resetVertexArray () |
Resets vertex coordinates. | |
void | setColorArray (InputArray color) |
Sets an array of vertex colors. | |
void | resetColorArray () |
Resets vertex colors. | |
void | setNormalArray (InputArray normal) |
Sets an array of vertex normals. | |
void | resetNormalArray () |
Resets vertex normals. | |
void | setTexCoordArray (InputArray texCoord) |
Sets an array of vertex texture coordinates. | |
void | resetTexCoordArray () |
Resets vertex texture coordinates. | |
void | release () |
Releases all inner buffers. | |
void | setAutoRelease (bool flag) |
Sets auto release mode all inner buffers. | |
void | bind () const |
Binds all vertex arrays. | |
int | size () const |
Returns the vertex count. | |
CV_EXPORTS void | 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. | |
CV_EXPORTS void | render (const Arrays &arr, int mode=POINTS, Scalar color=Scalar::all(255)) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
CV_EXPORTS void | render (const Arrays &arr, InputArray indices, int mode=POINTS, Scalar color=Scalar::all(255)) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
CV_EXPORTS Context & | initializeContextFromGL () |
Creates OpenCL context from GL. | |
CV_EXPORTS void | convertToGLTexture2D (InputArray src, Texture2D &texture) |
Converts InputArray to Texture2D object. | |
CV_EXPORTS void | convertFromGLTexture2D (const Texture2D &texture, OutputArray dst) |
Converts Texture2D object to OutputArray. | |
CV_EXPORTS UMat | mapGLBuffer (const Buffer &buffer, int accessFlags=ACCESS_READ|ACCESS_WRITE) |
Maps Buffer object to process on CL side (convert to UMat). | |
CV_EXPORTS void | unmapGLBuffer (UMat &u) |
Unmaps Buffer object (releases UMat, previously mapped from Buffer). | |
CV_EXPORTS void | setGlDevice (int device=0) |
Sets a CUDA device and initializes it for the current thread with OpenGL interoperability. |
Detailed Description
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).
Enumeration Type Documentation
enum RenderModes |
render mode
Definition at line 478 of file opengl.hpp.
Function Documentation
void bind | ( | Target | target ) | const [inherited] |
Binds OpenGL buffer to the specified buffer binding point.
- Parameters:
-
target Binding point. See cv::ogl::Buffer::Target .
void bind | ( | ) | const [inherited] |
Binds texture to current active texture unit for GL_TEXTURE_2D target.
void bind | ( | ) | const [inherited] |
Binds all vertex arrays.
Buffer | ( | int | arows, |
int | acols, | ||
int | atype, | ||
unsigned int | abufId, | ||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Buffer | ( | int | arows, |
int | acols, | ||
int | atype, | ||
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
arows Number of rows in a 2D array. acols Number of columns in a 2D array. atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
Buffer | ( | ) | [inherited] |
The constructors.
Creates empty ogl::Buffer object, creates ogl::Buffer object from existed buffer ( abufId parameter), allocates memory for ogl::Buffer object or copies from host/device memory.
Buffer | ( | Size | asize, |
int | atype, | ||
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
asize 2D array size. atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
Buffer | ( | InputArray | arr, |
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [explicit, inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
Buffer | ( | Size | asize, |
int | atype, | ||
unsigned int | abufId, | ||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
unsigned int bufId | ( | ) | const [inherited] |
get OpenGL opject id
Buffer clone | ( | Target | target = ARRAY_BUFFER , |
bool | autoRelease = false |
||
) | const [inherited] |
Creates a full copy of the buffer object and the underlying data.
- Parameters:
-
target Buffer usage for destination buffer. autoRelease Auto release mode for destination buffer.
CV_EXPORTS void cv::ogl::convertFromGLTexture2D | ( | const Texture2D & | texture, |
OutputArray | dst | ||
) |
CV_EXPORTS void cv::ogl::convertToGLTexture2D | ( | InputArray | src, |
Texture2D & | texture | ||
) |
void copyFrom | ( | InputArray | arr, |
bool | autoRelease = false |
||
) | [inherited] |
Copies from host/device memory to OpenGL texture.
- Parameters:
-
arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). autoRelease Auto release mode (if true, release will be called in object's destructor).
void copyFrom | ( | InputArray | arr, |
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
Copies from host/device memory to OpenGL buffer.
- Parameters:
-
arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
void copyFrom | ( | InputArray | arr, |
cuda::Stream & | stream, | ||
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void copyTo | ( | OutputArray | arr, |
int | ddepth = CV_32F , |
||
bool | autoRelease = false |
||
) | const [inherited] |
Copies from OpenGL texture to host/device memory or another OpenGL texture object.
- Parameters:
-
arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or ogl::Texture2D ). ddepth Destination depth. autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture).
void copyTo | ( | OutputArray | arr ) | const [inherited] |
Copies from OpenGL buffer to host/device memory or another OpenGL buffer object.
- Parameters:
-
arr Destination array (host or device memory, can be Mat , cuda::GpuMat , std::vector or ogl::Buffer ).
void copyTo | ( | OutputArray | arr, |
cuda::Stream & | stream | ||
) | const [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void create | ( | Size | asize, |
int | atype, | ||
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
asize 2D array size. atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
void create | ( | int | arows, |
int | acols, | ||
Format | aformat, | ||
bool | autoRelease = false |
||
) | [inherited] |
Allocates memory for ogl::Texture2D object.
- Parameters:
-
arows Number of rows. acols Number of columns. aformat Image format. See cv::ogl::Texture2D::Format . autoRelease Auto release mode (if true, release will be called in object's destructor).
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
asize 2D array size. aformat Image format. See cv::ogl::Texture2D::Format . autoRelease Auto release mode (if true, release will be called in object's destructor).
void create | ( | int | arows, |
int | acols, | ||
int | atype, | ||
Target | target = ARRAY_BUFFER , |
||
bool | autoRelease = false |
||
) | [inherited] |
Allocates memory for ogl::Buffer object.
- Parameters:
-
arows Number of rows in a 2D array. acols Number of columns in a 2D array. atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. target Buffer usage. See cv::ogl::Buffer::Target . autoRelease Auto release mode (if true, release will be called in object's destructor).
CV_EXPORTS Context& cv::ogl::ocl::initializeContextFromGL | ( | ) |
Creates OpenCL context from GL.
- Returns:
- Returns reference to OpenCL Context
cuda::GpuMat mapDevice | ( | ) | [inherited] |
map to device memory (blocking)
cuda::GpuMat mapDevice | ( | cuda::Stream & | stream ) | [inherited] |
Maps OpenGL buffer to CUDA device memory.
This operatation doesn't copy data. Several buffer objects can be mapped to CUDA memory at a time.
A mapped data store must be unmapped with ogl::Buffer::unmapDevice before its buffer object is used.
CV_EXPORTS UMat cv::ogl::mapGLBuffer | ( | const Buffer & | buffer, |
int | accessFlags = ACCESS_READ|ACCESS_WRITE |
||
) |
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() function.
- Parameters:
-
buffer - source Buffer object. accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE).
- Returns:
- Returns UMat object
Mat mapHost | ( | Access | access ) | [inherited] |
Maps OpenGL buffer to host memory.
mapHost maps to the client's address space the entire data store of the buffer object. The data can then be directly read and/or written relative to the returned pointer, depending on the specified access policy.
A mapped data store must be unmapped with ogl::Buffer::unmapHost before its buffer object is used.
This operation can lead to memory transfers between host and device.
Only one buffer object can be mapped at a time.
- Parameters:
-
access Access policy, indicating whether it will be possible to read from, write to, or both read from and write to the buffer object's mapped data store. The symbolic constant must be ogl::Buffer::READ_ONLY , ogl::Buffer::WRITE_ONLY or ogl::Buffer::READ_WRITE .
void release | ( | ) | [inherited] |
Decrements the reference counter and destroys the buffer object if needed.
The function will call setAutoRelease(true) .
void release | ( | ) | [inherited] |
Decrements the reference counter and destroys the texture object if needed.
The function will call setAutoRelease(true) .
void release | ( | ) | [inherited] |
Releases all inner buffers.
CV_EXPORTS void cv::ogl::render | ( | const Arrays & | arr, |
int | mode = POINTS , |
||
Scalar | color = Scalar::all(255) |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
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.
CV_EXPORTS 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.
- Parameters:
-
tex Texture to draw. wndRect Region of window, where to draw a texture (normalized coordinates). texRect Region of texture to draw (normalized coordinates).
CV_EXPORTS void cv::ogl::render | ( | const Arrays & | arr, |
InputArray | indices, | ||
int | mode = POINTS , |
||
Scalar | color = Scalar::all(255) |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
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.
void resetColorArray | ( | ) | [inherited] |
Resets vertex colors.
void resetNormalArray | ( | ) | [inherited] |
Resets vertex normals.
void resetTexCoordArray | ( | ) | [inherited] |
Resets vertex texture coordinates.
void resetVertexArray | ( | ) | [inherited] |
Resets vertex coordinates.
void setAutoRelease | ( | bool | flag ) | [inherited] |
Sets auto release mode.
The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was bound to a window it could be released at any time (user can close a window). If object's destructor is called after destruction of the context it will cause an error. Thus ogl::Buffer doesn't destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context). This function can force ogl::Buffer destructor to destroy OpenGL object.
- Parameters:
-
flag Auto release mode (if true, release will be called in object's destructor).
void setAutoRelease | ( | bool | flag ) | [inherited] |
Sets auto release mode.
- Parameters:
-
flag Auto release mode (if true, release will be called in object's destructor).
The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was bound to a window it could be released at any time (user can close a window). If object's destructor is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn't destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context). This function can force ogl::Texture2D destructor to destroy OpenGL object.
void setAutoRelease | ( | bool | flag ) | [inherited] |
Sets auto release mode all inner buffers.
- Parameters:
-
flag Auto release mode.
void setColorArray | ( | InputArray | color ) | [inherited] |
Sets an array of vertex colors.
- Parameters:
-
color array with vertex colors, can be both host and device memory.
CV_EXPORTS void cv::cuda::setGlDevice | ( | int | device = 0 ) |
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.
- Parameters:
-
device System index of a CUDA device starting with 0.
void setNormalArray | ( | InputArray | normal ) | [inherited] |
Sets an array of vertex normals.
- Parameters:
-
normal array with vertex normals, can be both host and device memory.
void setTexCoordArray | ( | InputArray | texCoord ) | [inherited] |
Sets an array of vertex texture coordinates.
- Parameters:
-
texCoord array with vertex texture coordinates, can be both host and device memory.
void setVertexArray | ( | InputArray | vertex ) | [inherited] |
Sets an array of vertex coordinates.
- Parameters:
-
vertex array with vertex coordinates, can be both host and device memory.
int size | ( | ) | const [inherited] |
Returns the vertex count.
unsigned int texId | ( | ) | const [inherited] |
get OpenGL opject id
Texture2D | ( | int | arows, |
int | acols, | ||
Format | aformat, | ||
unsigned int | atexId, | ||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Texture2D | ( | ) | [inherited] |
The constructors.
Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from host/device memory.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Texture2D | ( | int | arows, |
int | acols, | ||
Format | aformat, | ||
bool | autoRelease = false |
||
) | [inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
arows Number of rows. acols Number of columns. aformat Image format. See cv::ogl::Texture2D::Format . autoRelease Auto release mode (if true, release will be called in object's destructor).
Texture2D | ( | InputArray | arr, |
bool | autoRelease = false |
||
) | [explicit, inherited] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). autoRelease Auto release mode (if true, release will be called in object's destructor).
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
asize 2D array size. aformat Image format. See cv::ogl::Texture2D::Format . autoRelease Auto release mode (if true, release will be called in object's destructor).
static void unbind | ( | Target | target ) | [static, inherited] |
Unbind any buffers from the specified binding point.
- Parameters:
-
target Binding point. See cv::ogl::Buffer::Target .
void unmapDevice | ( | cuda::Stream & | stream ) | [inherited] |
Unmaps OpenGL buffer.
CV_EXPORTS void cv::ogl::unmapGLBuffer | ( | UMat & | u ) |
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() function.
- Parameters:
-
u - source UMat, created by mapGLBuffer().
void unmapHost | ( | ) | [inherited] |
Unmaps OpenGL buffer.
Generated on Tue Jul 12 2022 16:42:41 by 1.7.2