我想在OpenCV Mat中转换QVideoFrame。该帧以只读模式映射。
我编写了以下代码:
cv::Mat openCVBGRMatFrom(const QVideoFrame& frame)
{
auto width = frame.width();
auto height = frame.height();
auto* bits = const_cast<uchar*>(frame.bits());
cv::Mat result(height, width, CV_8UC3, cv::Scalar{0});
cv::Mat tmp{height + height/2, width, CV_8UC1, bits};
switch (frame.pixelFormat()) {
case QVideoFrame::Format_YUYV:
cv::cvtColor(tmp, result, cv::COLOR_YUV2BGR_YUYV);
break;
default:
throw std::runtime_error{"Unknown YUV pixel format"};
}
return result;
}
但是当我运行它时,出现以下运行时错误消息:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.0.0-pre) ../modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'
我认为这篇文章不是重复的,因为...我的代码有什么问题?