您的位置:首页 > 新闻 > 资讯 > 树莓派Qt调用摄像头报错记录(未解决)

树莓派Qt调用摄像头报错记录(未解决)

2025/1/8 1:27:51 来源:https://blog.csdn.net/m0_64386340/article/details/141283931  浏览:    关键词:树莓派Qt调用摄像头报错记录(未解决)

.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QCamera>
#include <QCameraViewfinder>
#include <QMediaRecorder>
#include <QVBoxLayout>#include <QCameraImageCapture>
#include <QCamera>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_scan_camera_clicked();void on_Star_camera_clicked();void on_Stop_camera_clicked();private:Ui::MainWindow *ui;QCamera *camera;QCameraViewfinder *viewfinder;QMediaRecorder *recorder;QCamera *ca;
};#endif // MAINWINDOW_H

 .cpp文件

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCameraInfo>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QPixmap>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);QList<QCameraInfo> infos = QCameraInfo::availableCameras();QString camera = infos.value(0).deviceName();ui->camera_cb->addItem(infos.value(0).description());ca =new QCamera(camera.toUtf8() ,this );ui->camera->show();QCameraViewfinder *v2 = new QCameraViewfinder(ui->camera);v2->resize(ui->camera->size());ca->setViewfinder(v2);v2->show();
}MainWindow::~MainWindow()
{//camera->stop();delete ui;
}void MainWindow::on_scan_camera_clicked()
{ui->camera_cb->clear();QList<QCameraInfo> infos = QCameraInfo::availableCameras();QString camera = infos.value(0).deviceName();ui->camera_cb->addItem(infos.value(0).description());
}void MainWindow::on_Star_camera_clicked()
{ca->start();
}void MainWindow::on_Stop_camera_clicked()
{ca->stop();
}

.ui界面

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com