PBO to cv::Mat

Hi,

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;
glGenBuffers(1,&pbo);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glBufferData(GL_PIXEL_PACK_BUFFER, img.colsimg.rows3, NULL, GL_DYNAMIC_READ);
glDeleteBuffers(1,&pbo);

OBJECT_TO_PBO

glFinish();
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
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”.

Thanks,
Pessanha24