1

From the documentation of Qt5 I get it that there are many widgets and classes that deal with camera input. On the other hand the documentation reads alot like intended for mobile phone cameras or even real cameras. With a viewfinder, record and snapshot buttons etc.

All I want is a widget inside my desktop Qt5 program that lets me see the video stream of my webcam (/dev/video0, v4l2). All parameters controlled via the code. Resolution, brightness and whatever the camera supports. No GUI elements.

Minimal but working code examples are appreciated. Either C++/Qt5 or pyqt5. But a hint which classes I should use in which connection would be a start as well.

Thank you very much!

P.S. Please, no answers that consists only(!) of a link to a documentation page as if that was self-explenatory. There is a camera example but did not help me much. Otherwise I would not have to ask here.

4

1 回答 1

3

像这样的文档http://qt-project.org/doc/qt-5/qtmultimediawidgets-camera-example.html真的是你所需要的。

最小的工作示例:(使用 pseye 摄像头在 ubuntu 上测试。如果这只是系统中的摄像头,则不必指定设备路径)

#include "mainwindow.h"
#include "ui_mainwindow.h"


#include <QCamera>
#include <QMediaPlayer>
#include <QVideoWidget>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    camera = new QCamera(this);
    videoWidget = new QVideoWidget();
    ui->mainLayout->addWidget(videoWidget);

    camera->setViewfinder(videoWidget);
    camera->start();
}

MainWindow::~MainWindow()
{
    delete ui;
}
于 2014-04-25T06:10:14.037 回答