Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7403

Camera board • Obtaining ROI of YUV420p image stream during post-processing

$
0
0
Here's a scenario. I currently working on custom post-processing script that will draw a semi-transparent rectangle with multiple text overlays on the bottom-right corner of every video frame. (Target is to record the video at 1080p 30fps)

I wanted to set an ROI at the bottom-right corner of the image, so that I can perform the following tasks in Process() function:
  • Convert that ROI from YUV420p to RGB
  • Draw a semi-transparent rectangle with multiple text overlays on that ROI
  • Convert back that ROI from RGB to YUV420p
Right now, I'm currently stuck on getting the ROI from the YUV420 image stream in Process() function. Here's the rough source code.

Code:

BufferWriteSync w(app_, completed_request->buffers[stream_]);libcamera::Span<uint8_t> buffer = w.Get()[0];FrameInfo info(completed_request);uint8_t *ptr = (uint8_t *)buffer.data();Mat background(info_.height, info_.width, CV_8U, ptr, info_.stride);// This is where I run into the runtime error// terminate called after throwing an instance of 'cv::Exception'//  what():  OpenCV(4.6.0) ./modules/imgproc/src/color.simd_helpers.hpp:108: error: (-215:Assertion failed) sz.width % 2 == 0 && sz.height % 3 == 0 in function 'CvtHelper'Rect roi(50, 50, 100, 100);Mat roiImage = background(roi);Mat rgbImage;cvtColor(roiImage, rgbImage, COLOR_YUV420p2RGB);
Please help.

Statistics: Posted by ongeelim — Mon Aug 19, 2024 2:02 pm — Replies 1 — Views 37



Viewing all articles
Browse latest Browse all 7403

Trending Articles