QT5 基于v4l2的简易照相机,不显示实时摄像头,拍照以yuv格式存储
以下为代码
main.cpp:
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->quitButton, SIGNAL(clicked()), this, SLOT(clickQuitButton()));
connect(ui->photoButton, SIGNAL(clicked()), this, SLOT(clickPhotoButton()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::clickQuitButton(void)
{
this->close();
}
void MainWindow::clickPhotoButton(void)
{
v4l2.V4l2_Init();
v4l2.V4l2_Malloc();
v4l2.V4l2_capturing();
v4l2.Take_photo();
v4l2.V4l2_Close();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include"v4l2.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void clickQuitButton(void);
void clickPhotoButton(void);
private:
Ui::MainWindow *ui;
V4L2 v4l2;
};
#endif // MAINWINDOW_H
v4l2.cpp:
#include "v4l2.h"
V4L2::V4L2()
{
}
V4L2::~V4L2()
{
}
bool V4L2::V4l2_Init(void)
{
if((fd=open(Video_path,O_RDWR)) == -1) //读写方 式打开摄像头
{
qDebug()<<"Error opening V4L interface"; //打印错误 信息
return false;
}
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == -1) //获取摄 像头详细参数
{