简体   繁体   中英

QVideoWidget doesn't display frames

I created a subclass of QVideoWidget in order to display Video Frames from a camera (Basler, Pylon C++ API). Briefly, frames are converted to cv::Mat and then analyzed by a Neural Network. After that, I subclassed a QAbstractVideoSurface that presents frame to the 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. 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. I really suspect my paintEvent function.

Here is my 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.

You dont need to subclass QVideoWidget for this. Convert frame to image and present it on QVideoWidget::videoSurface() like documentation says

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM