I want to load an image to GPU memory for fast speed processing

Hi, All.

I want to load an image to GPU memory for fast speed processing.

And, I want to crop with my own ROI location in GPU.

How can I get this using OF?

Thanks in advance.

Best,
@bemoregt.

Typically images are represented in the GPU as a texture. In OF this is abstracted using an ofTexture. You can load images directly into ofTexture. For example:

https://openframeworks.cc/documentation/graphics/ofImage/#show_ofLoadImage

ofTexture tex;
ofLoadImage(tex, "path/to/image.png")

// Reference texture in a shader, etc.

A texture is also available if you load an image into an ofImage via ofImage::getTexture().

To crop a texture to a specific ROI, you can do so before you upload it to the texture (e.g. load the image it into ofPixels and call ofPixels::crop or ofPixels::cropTo, then ofTexture::loadData) or you can pass the ROI coordinates to a shader as a set of uniform variables. Then you could write a shader that would only process the passed ROI.

To simply display a texture ROI on screen, you can display a subsection (see ofTexture::drawSubsection reference).

All of this assumes that you want to manipulate images on the GPU using shaders. If you want to manipulate images on the GPU via another method (e.g. OpenCL, CUDA, GPGPU, etc) then you might need to take a different approach.

1 Like