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;
UMat image_;
UMat converted_;
public:
//Loads an image as a UMat (just in case we have hardware acceleration available)
#ifdef __EMSCRIPTEN__
image = read_embedded_image("doc/lena.png").getUMat(ACCESS_READ);
#else
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.
resize(image, converted, sz);
cvtColor(converted, converted, COLOR_RGB2BGRA);
}, image_, converted_, win->fbSize());
}
//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
c.copyTo(framebuffer);
}, converted_);
}
};
int main() {
//Creates a V4D object
Ptr<V4D> window = V4D::make(960, 960, "Display an Image through direct FB access");
window->run<DisplayImageFB>(0);
}
UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags=USAGE_DEFAULT) const
retrieve UMat from Mat
Definition: mat.hpp:2432
Definition: v4d.hpp:68
Definition: backend.hpp:15
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106