[英]Transform a YUV420p QVideoFrame into grayscale OpenCV mat
I've created a filter extending QAbstractVideoFilter
and QVideoFilterRunnable
and I've overrided the我创建了一个扩展QAbstractVideoFilter
和QVideoFilterRunnable
的过滤器,并且我已经覆盖了
QVideoFrame run(QVideoFrame* input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)`
method方法
The problem is that QVideoFrame
format is Format_YUV420P
and has no handle.问题是QVideoFrame
格式是Format_YUV420P
,没有句柄。 I need to convert it into a CV_8UC1
in order to use OpenCV
algorithms.我需要将其转换为CV_8UC1
才能使用OpenCV
算法。
Which is the best way to accomplish this?实现这一目标的最佳方法是什么?
First you need to create a cv::Mat
which has an API for initializing using data pointer as:首先,您需要创建一个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*/)
Now since the img
is initialized with YUV color data, you may use various cvtColor
modes to convert the YUV mat to other formats, for converting it to gray-scale you may try:现在由于img
是用 YUV 颜色数据初始化的,您可以使用各种cvtColor
模式将 YUV mat 转换为其他格式,将其转换为灰度,您可以尝试:
cv::Mat gray;
cv::cvtColor(img, gray, cv::COLOR_YUV2GRAY_I420);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.