• 大小: 164KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-11
  • 语言: 其他
  • 标签: linux  V4L2  Qt  usb  摄像头  

资源简介

linux下基于V4L2/Qt的usb摄像头采集显示程序
Qt工程, 测试使用的是Qt5.6.0
可以正常使用, 采集usb摄像头的图像并显示, 可以正常配置摄像头像素

资源截图

代码片段和文件信息

#include “camera.h“
#include “ui_camera.h“
#include “libv4l/include/libv4l2.h“
#include “libv4l/include/libv4lconvert.h“

#include 
#include 

Camera::Camera() : ui(new Ui::Camera)
{
    ui->setupUi(this);
    setGeometry(0 0 1024 600);

    // fps display init
    fps_label = new QLabel(“fps: 0 Hz“ this);
    statusBar()->addPermanentWidget(fps_label);
    timer = new QTimer(this);
    connect(timer SIGNAL(timeout()) this SLOT(update_fps()));

    video_ops = new v4l2_ops();

    QDir dir(“/dev“);
    QStringList dev = dir.entryList(QDir::System);
    for (int i = 0; i < dev.size(); ++i) {
        QString one = dev.at(i).trimmed();
        if (one.contains(“video“)) {
            ui->comboBox->addItem(one);
        }
    }
}

void Camera::startCamera()
{
    connect(video_ops SIGNAL(get_one_frame(QImage)) this SLOT(get_one_frame(QImage)));
    video_ops->open(ui->comboBox->currentText());
    frame_count = 0;

    // init info
    ui->lineEdit->setText(video_ops->dev_name);
    ui->lineEdit_2->setText(video_ops->dri_name);
    ui->lineEdit_3->setText(video_ops->card_name);
    ui->lineEdit_4->setText(video_ops->bus_info);
    ui->lineEdit_5->setText(QString(“%1x%2“).arg(video_ops->cur_resolutin.width()).arg(video_ops->cur_resolutin.height()));

    // init setting Image Format:
    ui->comboBox_2->clear();
    for (int i = 0; i < video_ops->list_fmt_info.size(); i++) {
        fmt_info *node = video_ops->list_fmt_info.at(i);
        ui->comboBox_2->addItem(node->fmt_desc QVariant(node->list_resolutin));
    }

    ui->takeImageButton->setEnabled(true);
    ui->actionstartCamera->setEnabled(false);
    ui->actionstopCamera->setEnabled(true);
    ui->captureWidget->setEnabled(true);

    ui->label_2->clear();
    displayV4l2();
}

void Camera::stopCamera()
{
    if (video_ops->isRunning()) {
        disconnect(video_ops SIGNAL(get_one_frame(QImage)) this SLOT(get_one_frame(QImage)));
        video_ops->close();
        qDebug() << “stopCamera“;
    }

    fps_label->setText(“fps: 0 Hz“);
    timer->stop();

    ui->comboBox_2->clear();
    ui->comboBox_3->clear();
    ui->actionstartCamera->setEnabled(true);
    ui->actionstopCamera->setEnabled(false);
    ui->captureWidget->setEnabled(false);

    ui->label_2->clear();
}

void Camera::get_one_frame(QImage img)
{
//    qDebug() << “get one frame“;
    if (!timer->isActive()) {
        timer->start(1000);
    }
    if (ui->stackedWidget->currentIndex() == 1) {
        last_image = img;
        ui->label_2->setPixmap(QPixmap::fromImage(img.scaled(ui->label_2->size())));
    }
    frame_count++;
}


void Camera::takeImage()
{
    ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(last_image.scaled(ui->lastImagePreviewLabel->size() Qt::KeepAspectRatio Qt::SmoothTransformation)));

    // Display captured image for 4 seconds.
    displayCapturedImage();
    QTime

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-01-12 15:18  qcamera_v4l2_lib\
     文件        4399  2020-01-12 15:07  qcamera_v4l2_lib\camera.cpp
     文件         878  2020-01-12 15:08  qcamera_v4l2_lib\camera.h
     文件       15326  2020-01-06 22:47  qcamera_v4l2_lib\camera.ui
     目录           0  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\
     文件       20060  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\ChangeLog
     文件       26941  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\COPYING.LIB
     目录           0  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\include\
     文件        2932  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\include\libv4l1.h
     文件        4794  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\include\libv4l2.h
     文件        4787  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\include\libv4lconvert.h
     目录           0  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l1\
     文件        2262  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l1\libv4l1-priv.h
     文件       25455  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l1\libv4l1.c
     文件        5912  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l1\log.c
     文件        3053  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l1\v4l1compat.c
     目录           0  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l2\
     文件        3021  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l2\libv4l2-priv.h
     文件       46260  2019-10-25 23:07  qcamera_v4l2_lib\libv4l\libv4l2\libv4l2.c
     文件        8296  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l2\log.c
     文件        4143  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4l2\v4l2convert.c
     目录           0  2019-10-25 22:38  qcamera_v4l2_lib\libv4l\libv4lconvert\
     文件       18539  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\bayer.c
     目录           0  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\control\
     文件        2495  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\control\libv4lcontrol-priv.h
     文件       24391  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\control\libv4lcontrol.c
     文件        2892  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\control\libv4lcontrol.h
     文件        9998  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\crop.c
     文件        7424  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\flip.c
     文件        2508  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\helper-funcs.h
     文件        6484  2019-10-25 22:19  qcamera_v4l2_lib\libv4l\libv4lconvert\helper.c
............此处省略33个文件信息

评论

共有 条评论