繁体   English   中英

将 YUV420p QVideoFrame 转换为灰度 OpenCV mat

[英]Transform a YUV420p QVideoFrame into grayscale OpenCV mat

我创建了一个扩展QAbstractVideoFilterQVideoFilterRunnable的过滤器,并且我已经覆盖了

QVideoFrame run(QVideoFrame* input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)`

方法

问题是QVideoFrame格式是Format_YUV420P ,没有句柄。 我需要将其转换为CV_8UC1才能使用OpenCV算法。

实现这一目标的最佳方法是什么?

首先,您需要创建一个cv::Mat ,它具有用于使用数据指针初始化的API

cv::Mat img = cv::Mat(rows, cols, CV_8UC3, input.data/*Change this to point the first element of array containing the YUV color info*/)

现在由于img是用 YUV 颜色数据初始化的,您可以使用各种cvtColor模式将 YUV mat 转换为其他格式,将其转换为灰度,您可以尝试:

cv::Mat gray;
cv::cvtColor(img, gray, cv::COLOR_YUV2GRAY_I420);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM