Loading...
Searching...
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
Downloading...
using namespace cv;
using namespace cv::v4d;
class DisplayImagePlan : public Plan {
UMat image_;
public:
void setup(Ptr<V4D> win) override {
win->parallel([](cv::UMat& image){
#ifdef __EMSCRIPTEN__
image = read_embedded_image("doc/lena.png").getUMat(ACCESS_READ);
#else
image = imread(samples::findFile("lena.jpg")).getUMat(ACCESS_READ);
#endif
}, image_);
}
void infer(Ptr<V4D> win) override {
//Feeds the image to the video pipeline
win->feed(image_);
}
};
int main() {
//Creates a V4D window for on screen rendering with a window size of 960x960 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");
window->run<DisplayImagePlan>(0);
}
UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags=USAGE_DEFAULT) const
retrieve UMat from Mat
Definition: mat.hpp:2432
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