crop video frames to aspect in HTML5Capture

pull/3471/head
kallaballa 2 years ago
parent 51d2ed99b3
commit 242ee75982
  1. 9
      modules/v4d/src/util.cpp

@ -421,7 +421,7 @@ private:
GLuint texture = 0;
public:
HTML5Capture(cv::Ptr<V4D> 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;
}

Loading…
Cancel
Save