0

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.

1 Answers1

0

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();
mugiseyebrows
  • 4,138
  • 1
  • 14
  • 15
  • Hi, it makes things easier, but the frame is still not displayed. But that's a great improvement in a way. – paulopepito Jan 27 '21 at 20:00
  • When I put `m_videoWidget->videoSurface()->present(frame);` in a slot, `m_videoWidget->videoSurface()->error()` gives me: `StoppedError`. I start the surface before. Do we agree that I need to call `present()` each time a new frame had been grabbed? – paulopepito Jan 28 '21 at 21:49