#include #ifndef __EMSCRIPTEN__ # include #endif using namespace cv; using namespace cv::v4d; int main() { Ptr window = V4D::make(960, 960, "Custom Source/Sink"); string hr = "Hello Rainbow!"; //Make a source that generates rainbow frames. Source src([](cv::UMat& frame){ static long cnt = 0; //The source is responsible for initializing the frame.. if(frame.empty()) frame.create(Size(960, 960), CV_8UC3); frame = colorConvert(Scalar(++cnt % 180, 128, 128, 255), COLOR_HLS2BGR); return true; }, 60.0f); //Make a sink the saves each frame to a PNG file (does nothing in case of WebAssembly). Sink sink([](const uint64_t& seq, const cv::UMat& frame){ try { #ifndef __EMSCRIPTEN__ imwrite(std::to_string(seq) + ".png", frame); #else CV_UNUSED(frame); #endif } catch(std::exception& ex) { cerr << "Unable to write frame: " << ex.what() << endl; return false; } return true; }); //Attach source and sink window->setSource(src); window->setSink(sink); window->run([hr](cv::Ptr win) { if(!win->capture()) return false; //Render "Hello Rainbow!" over the video win->nvg([](const Size& sz, const string& str) { 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, str.c_str(), str.c_str() + str.size()); }, win->fbSize(), hr); win->write(); return win->display(); }); }