PBO to cv::Mat


Basically I need to render an object using OPENGL and read it back to the CPU for post-processing. I need to make this process as fast as possible since it will be used for object tracking in a particle filtering framework.

Actually I render the object in a window and read it back with success using glReadPixels(), but this is a very slow process.

To increase speed I´m trying to transfer the object data to a PBO, and then transferring it to the CPU in form of a cv::Mat variable (OPENCV)

PBO Initialization:

GLuint pbo;
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glBufferData(GL_PIXEL_PACK_BUFFER, img.colsimg.rows3, NULL, GL_DYNAMIC_READ);


glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glReadPixels(0,0, img.cols, img.rows,GL_BGR,GL_UNSIGNED_BYTE,0);

I don’t know if I´m doing it right because I try to transfer the PBO to a CV::MAT using glMapBuffer() without success.

Any suggestion or comment will be welcome to help me solve this issue.

If you know a different approach that allows me to obtain speed in this process that help will be “precious”.