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.
Downloading...
#include <opencv2/v4d/v4d.hpp>
#include <opencv2/imgcodecs.hpp>
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
#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
Definition: framebuffercontext.hpp:25
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106