Loading...
Searching...
No Matches
Display an image using direct framebuffer access

Prev Tutorial: Display an image using the video pipeline
Next Tutorial: Display an image using NanoVG

Original author Amir Hassan (kallaballa) amir@.nosp@m.viel.nosp@m.-zu.o.nosp@m.rg
Compatibility OpenCV >= 4.7

Using direct framebuffer access

Instead of feeding to the video pipeline we can request the framebuffer in a fb context and copy the image to it. But first we must manually resize and color convert the image.

Display an Image through the FB Context
Downloading...
using namespace cv;
using namespace cv::v4d;
int main() {
//Creates a V4D object
Ptr<V4D> window = V4D::make(960, 960, "Display an Image through direct FB access", false, false, 0);
//Loads an image as a UMat (just in case we have hardware acceleration available)
#ifdef __EMSCRIPTEN__
UMat image = read_embedded_image("doc/lena.png").getUMat(ACCESS_READ);
#else
UMat image = imread(samples::findFile("lena.jpg")).getUMat(ACCESS_READ);
#endif
//We have to manually resize and color convert the image when using direct frambuffer access.
UMat resized;
UMat converted;
resize(image, resized, window->framebufferSize());
cvtColor(resized, converted, COLOR_RGB2BGRA);
window->run([converted](Ptr<V4D> win){
//Create a fb context and copy the prepared image to the framebuffer. The fb context
//takes care of retrieving and storing the data on the graphics card (using CL-GL
//interop if available), ready for other contexts to use
win->fb([&](UMat& framebuffer){
converted.copyTo(framebuffer);
});
return win->display();
});
}
UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags=USAGE_DEFAULT) const
retrieve UMat from Mat
Definition: mat.hpp:2432
void copyTo(OutputArray m) const
copies the matrix content to "m".
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
Definition: framebuffercontext.hpp:25
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106