将QVideoFrame转换为QImage [英] convert QVideoFrame to QImage

查看:67
本文介绍了将QVideoFrame转换为QImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 QMediaPlayer 获取每帧并将其转换为 QImage (或 cv :: Mat )

I want to get every frames from a QMediaPlayer and convert it to QImage (or cv::Mat)

所以我使用了来自 QVideoProbe videoFrameProbed 信号:

so I used videoFrameProbed signal from QVideoProbe:

connect(&video_probe_, &QVideoProbe::videoFrameProbed, 
         [this](const QVideoFrame& currentFrame){
   //QImage img = ??
}

但是我没有找到从 QVideoFrame 中获取 QImage 的任何方法!

But I didn't find any way for getting QImage from QVideoFrame!

如何将 QVideoFrame 转换为 QImage ?!

推荐答案

您可以使用QImage的构造函数:

You can use QImage's constructor:

 QImage img( currentFrame.bits(),
             currentFrame.width(),
             currentFrame.height(),
             currentFrame.bytesPerLine(),
             imageFormat);

从哪里可以从 QVideoFrame pixelFormat 获得 imageFormat :

 QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(currentFrame.pixelFormat());

这篇关于将QVideoFrame转换为QImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆