c++ - 将 QVideoFrame 转换为 QImage

标签 c++ qt qimage

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

所以我使用了来自 QVideoProbevideoFrameProbed 信号:

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

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

如何将 QVideoFrame 转换为 QImage ?!

最佳答案

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

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

在哪里可以从 QVideoFramepixelFormat 获取 imageFormat:

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

关于c++ - 将 QVideoFrame 转换为 QImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27829830/

相关文章:

c++ - 神秘的编译错误: cannot convert from 'const boost::shared_ptr<T>' to 'const boost::shared_ptr<T>'

c++ - QFile 类嵌套的问题

c++ - 更新图像显示时的QImage和openmp

c++ - 书中的代码未运行 - 旧语法或错误代码?

c++ - clang 似乎没有链接到库

c++ - sizeof(空白类)== 1. 为什么?

c++ - 系统范围的热键快捷方式(Windows/Qt) : Prevent window lock?

qt - 如何子类化一个小部件以向其添加更多元素?

c++ - 如何检测 QImage 消耗最少 RAM 的足够格式(数据类型)?

qt - 在OpenGL中使用QImage