From 242ee75982a77380accc824e93d65b76469c2ce3 Mon Sep 17 00:00:00 2001 From: kallaballa Date: Sun, 24 Sep 2023 13:31:18 +0200 Subject: [PATCH] crop video frames to aspect in HTML5Capture --- modules/v4d/src/util.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/v4d/src/util.cpp b/modules/v4d/src/util.cpp index 9ecfb3954..ff86dbf5f 100644 --- a/modules/v4d/src/util.cpp +++ b/modules/v4d/src/util.cpp @@ -421,7 +421,7 @@ private: GLuint texture = 0; public: HTML5Capture(cv::Ptr window, int width, int height) : - window_(window), width_(width), height_(height), fb_(cv::Size(width, height), CV_8UC4) { + window_(window), width_(width), height_(height), fb_(window->framebufferSize(), CV_8UC4) { EM_ASM({ globalThis.playing = false; globalThis.timeupdate = false; @@ -476,7 +476,12 @@ public: ); FrameBufferContext::FrameBufferScope fbScope(window_->fbCtx(), fb_); flip(fb_, fb_, 0); - cvtColor(fb_, dst, COLOR_BGRA2RGB); + if(dst.empty()) + dst.create(fb_.size(), CV_8UC3); + + dst = cv::Scalar(0, 0, 0, 255); + cvtColor(fb_(cv::Rect(0, 0, width_, height_)), dst(cv::Rect((fb_.size().width - width_)/2.0, (fb_.size().height - height_)/2.0, width_, height_)), COLOR_BGRA2RGB); + cvtColor(dst, fb_, COLOR_RGB2BGRA); return true; }