Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

c++ - 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.

question from:https://stackoverflow.com/questions/65910004/qvideowidget-doesnt-display-frames

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...