将 YUV420p QVideoFrame 转换为灰度 OpenCV 垫
Transform a YUV420p QVideoFrame into grayscale OpenCV mat
我创建了一个扩展QAbstractVideoFilter
和 QVideoFilterRunnable
,我已经覆盖了
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 垫转换为其他格式,要将其转换为灰度,您可以尝试:
cv::Mat gray;
cv::cvtColor(img, gray, cv::COLOR_YUV2GRAY_I420);
相关文章:
- OpenCV - 如何在灰度图像上应用 Kmeans?
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- 使用 OpenCV 和 C++将 16 位灰度图像更改为彩色图像
- 如何在OpenCV中减去两个不同尺寸的图像和灰度图像
- C++:灰度位图标题和实时绘画+opencv图像处理
- 如何正确将位图转换为 OpenCV 灰度垫
- 将 YUV420p QVideoFrame 转换为灰度 OpenCV 垫
- 在OpenCV中将灰度图像转换为单色
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 使用条款 使用Opencv和Qt减去两个灰度图像
- OPENCV从Yuyv Pixelformat视频框架创建YUV420或灰度垫子对象
- OPENCV:从RGB转换为灰度只有蓝色
- 使用OpenCV在Android上使用神经网络进行灰度图像分类
- 如何在 OpenCV 中使用 16 位灰度
- 使用Opencv直接从网络摄像头获取灰度图像
- 将颜色图像转换为OpenCV中的灰度问题
- 在 openCV 中访问某些像素的强度值(灰度图像)
- Qt + OpenCV 灰度误差
- 转换实时视频帧灰度(OpenCV)
- 将灰度OpenCV图像传递到OpenGL纹理