Ya, the CPlusPlus TOP would be faster in the long run since it requires less GPU->GPU memory copies, but a bit more work.
To get started with the CPlusPlus TOP you'd first need to get your image data from the input texture into CPU memory. Then you'd run your OpenCV code, and finally upload the resulting image to the output. To do this you'd run this code in the execute() function
- Code: Select all
// Allocate pace for width*height*3channels,
// you'll want to cache this as a member of your class to avoid allocating it
// every frame
unsigned char *imageData = new char[arrays->TOPInputs.width * arrays->TOPInputs.height * 3];
// Bind the texture
// Download the texture into imageData
// GL_BGR is far faster than GL_RGB, use a Reorder TOP before the CPlusPlus TOP
// if your OpenCV usage requires proper channel ordering.
::glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR, GL_UNSIGNED_BYTE, imageData);
// Run your openCV code here on image data
// Upload back to the output framebuffer.
// This assumes your input resolution is the same as your output.
::glDrawPixels(arrays->TOPInputs.width, arrays->TOPInputs.height, GL_BGR, GL_UNSIGNED_BYTE, openCVOutputImageData);
This is the basic code that will get you started. It won't be fast since downloading from the GPU will stall the rendering pipeline. Once you have this working post again and we can go into using pixel_buffer_objects to do asynchronous uploads/downloads.
It's also important to note that your resolution width should be a multiple of 4. If it's not then you'll need deal with byte-alignment issues using glPixelStorei(), which I can get into if needed also (since OpenCV requires pixel rows to be a multiple of 4 bytes in size )
This seems like a common enough issue that I should add the ability to do the download for you manually. I'll add an RFE for that for our next major release.