C++ 强制Qt摄像机视频格式
我正在尝试使用QML的Qt摄像机 我正在开发一个自定义视频过滤器:C++ 强制Qt摄像机视频格式,c++,qt,opencv,camera,qml,C++,Qt,Opencv,Camera,Qml,我正在尝试使用QML的Qt摄像机 我正在开发一个自定义视频过滤器: QVideoFrame MyFilterRunnable::run(QVideoFrame*输入,const QVideoSurfaceFormat&,RunFlags) 我开始在Windows上部署应用程序,我有: 帧在QAbstractVideoBuffer::ReadWrite中可映射 帧像素格式为PixelFormat::format_BGR32 不幸的是,当我搬到Linux时,一切都变了,我没有更换相机: 帧仅为
QVideoFrame MyFilterRunnable::run(QVideoFrame*输入,const QVideoSurfaceFormat&,RunFlags)
我开始在Windows上部署应用程序,我有:
- 帧在
QAbstractVideoBuffer::ReadWrite中可映射
- 帧像素格式为
PixelFormat::format_BGR32
- 帧仅为
QAbstractVideoBuffer::ReadOnly
- 帧像素格式为
PixelFormat::format\u YUYV
Mat
有没有办法选择相机的像素格式?我的Linux机器和Raspberry之间面临着同样的问题:我使用的是同一台相机,QVideoFrame的像素格式gven是不同的。它可能与v4l2有关 关于从YUYV到OpenCV Mat的转换,以下代码对我很有用:
QVideoFrame *input ;
...
auto input_w = input->width ();
auto input_h = input->height();
auto cam_data = input->bits();
cv::Mat yuyv(input_h, input_w,CV_8UC2, cam_data);
cv::Mat rgb (input_h, input_w,CV_8UC3);
cvtColor(yuyv, rgb, CV_YUV2BGR_YUYV);
没错,史蒂文
if (input->pixelFormat() == QVideoFrame::Format_YUYV)
{
auto input_w = input->width ();
auto input_h = input->height();
auto cam_data = input->bits();
cv::Mat yuyv(input_h, input_w,CV_8UC2, cam_data);
cv::Mat rgb (input_h, input_w,CV_8UC3);
cvtColor(yuyv, rgb, CV_YUV2BGR_YUYV);
m_mat = rgb;
}
else
if (input->pixelFormat() == QVideoFrame::Format_YUV420P || input->pixelFormat() == QVideoFrame::Format_NV12) {
m_yuv = true;
m_mat = yuvFrameToMat8(*input);
} else {
m_yuv = false;
QImage wrapper = imageWrapper(*input);
if (wrapper.isNull()) {
if (input->handleType() == QAbstractVideoBuffer::NoHandle)
input->unmap();
return *input;
}
m_mat = imageToMat8(wrapper);
}
ensureC3(&m_mat);