Loading...
Searching...
No Matches
Video editing
Prev Tutorial: Font rendering
Next Tutorial: Custom Source and Sink
Original author | Amir Hassan (kallaballa) amir@.nosp@m.viel.nosp@m.-zu.o.nosp@m.rg |
Compatibility | OpenCV >= 4.7 |
Render text on top of a video
Through adding a source and a sink v4d becomes capable of video editing. Reads a video, renders text on top and writes the result. Note: Reading and writing of video-data is multi-threaded in the background for performance reasons.
Downloading...
#include <opencv2/v4d/v4d.hpp>
using namespace cv;
using namespace cv::v4d;
int main(int argc, char** argv) {
//In case of WebAssembly
CV_UNUSED(argc);
CV_UNUSED(argv);
string hv = "Hello Video!";
#ifndef __EMSCRIPTEN__
//Make the video source
Source src = makeCaptureSource(argv[1]);
//Make the video sink
//Attach source and sink
window->setSource(src);
window->setSink(sink);
#else
//Make a webcam Source
Source src = makeCaptureSource(960, 960, window);
//Attach webcam source
window->setSource(src);
#endif
window->run([hv](Ptr<V4D> win) {
//Capture video from the source
if(!win->capture())
return false; //end of input video
//Render on top of the video
win->nvg([hv](const Size& sz) {
using namespace cv::v4d::nvg;
fontSize(40.0f);
fontFace("sans-bold");
fillColor(Scalar(255, 0, 0, 255));
textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
text(sz.width / 2.0, sz.height / 2.0, hv.c_str(), hv.c_str() + hv.size());
});
//Write video to the sink (do nothing in case of WebAssembly)
win->write();
return win->display();
});
}
Definition: sink.hpp:19
Definition: source.hpp:20
float fps()
Definition: framebuffercontext.hpp:25
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106