No Matches
Display an image using the video pipeline

Prev Tutorial: V4D
Next Tutorial: Display an image using direct framebuffer access

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

Using the video pipeline

Actually there are several ways to display an image using V4D. The most convenient way is to use the video pipeline to feed an image to V4D. That has the advantage that the image is automatically resized (preserving aspect ratio) to framebuffer size and color converted (the framebuffer is BGRA while video frames are expected to be BGR).

Display an Image through the Video-Pipeline
using namespace cv;
using namespace cv::v4d;
int main() {
//Creates a V4D window for on screen rendering with a window size of 720p and a framebuffer of the same size.
//Please note that while the window size may change the framebuffer size may not. If you need multiple framebuffer
//sizes you need multiple V4D objects
cv::Ptr<V4D> window = V4D::make(960, 960, "Display an Image", 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);
UMat image = imread(samples::findFile("lena.jpg")).getUMat(ACCESS_READ);;
//Display the framebuffer in the native window in an endless loop.
//V4D::run() though it takes a functor is not a context. It is simply an abstraction
//of a run loop for portability reasons and executes the functor until the application
//terminates or the functor returns false.
window->run([image](Ptr<V4D> win){
//Feeds the image to the video pipeline
//Displays the framebuffer in the window. Returns false if the windows has been closed.
return win->display();
UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags=USAGE_DEFAULT) const
retrieve UMat from Mat
Definition: mat.hpp:2432
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