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;
class DisplayImageFB : public Plan {
UMat image_;
UMat converted_;
public:
void setup(cv::Ptr<V4D> win) override {
win->parallel([](cv::UMat& image, cv::UMat& converted, const cv::Size& sz){
//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());
}
void infer(Ptr<V4D> win) override {
//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, const cv::UMat& c){
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
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
Definition: mat.hpp:2432
void copyTo(OutputArray m) const
copies the matrix content to "m".
Definition: v4d.hpp:68
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
Definition: backend.hpp:15
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106