[英]QVideoWidget doesn't display frames
I created a subclass of QVideoWidget
in order to display Video Frames from a camera (Basler, Pylon C++ API).我创建了
QVideoWidget
的一个子类,以便显示来自相机的视频帧(Basler、Pylon C++ API)。 Briefly, frames are converted to cv::Mat
and then analyzed by a Neural Network.简而言之,帧被转换为
cv::Mat
,然后由神经网络进行分析。 After that, I subclassed a QAbstractVideoSurface
that presents frame to the VideoWidget.之后,我将一个
QAbstractVideoSurface
子类化,将帧呈现给 VideoWidget。
When I try to display my frame in the QVideoWidget, the function void paintEvent(QPaintEvent *event)
is triggered by update()
or repaint()
, but nothing is displayed on the widget.当我尝试在 QVideoWidget 中显示我的帧时,function
void paintEvent(QPaintEvent *event)
由update()
或repaint()
触发,但小部件上没有显示任何内容。 What's wrong?怎么了?
I checked from the beginning of the pipeline, to the end, everything is OK (the frame contains data, the pixel format is OK, size OK, I can save a video file with actual frames in it, etc ).我从管道开始检查到最后,一切正常(帧包含数据,像素格式正常,大小正常,我可以保存一个包含实际帧的视频文件,等等)。 I can see the widget in UI.
我可以在 UI 中看到小部件。 I really suspect my paintEvent function.
我真的怀疑我的paintEvent function。
Here is my paintEvent(QPaintEvent *event) function:这是我的paintEvent(QPaintEvent *event) function:
// VideoWidget.h
protected:
void paintEvent(QPaintEvent *event) override;
// VideoWidget.cpp
void VideoWidget::paintEvent(QPaintEvent *event) {
QPainter p(this);
p.drawImage(QRectF(m_targetRect), m_frameConv);
QVideoWidget::paintEvent(event);
}
PS: I'm on MacOS 11 (it didn't work neither on MacOSX), I'm using CMake 3.17. PS:我在 MacOS 11 上(它在 MacOSX 上也不起作用),我正在使用 CMake 3.17。
You dont need to subclass QVideoWidget
for this.您不需要为此
QVideoWidget
。 Convert frame to image and present it on QVideoWidget::videoSurface()
like documentation says将帧转换为图像并将其呈现在
QVideoWidget::videoSurface()
上,如文档所述
videoWidget = new QVideoWidget;
QVideoSurfaceFormat format(imgSize, QVideoFrame::Format_ARGB32);
videoWidget->videoSurface()->start(format);
QImage img = frameToImage(m_frameConv).convertToFormat(QImage::Format_ARGB32);
videoWidget->videoSurface()->present(img);
videoWidget->show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.