资源简介

最近在研究二维码识别,看了很多博客,学到了许多,这里就不一一发出链接了CSDN中一搜一堆,我第一次用手机发博,不太会用,就简单发个近两天研究总结,虽然两天就搞出来了,但是感觉水分很大。直接上代码和视频效果吧 对应文章见此链接https://blog.csdn.net/qq_37603131/article/details/89199138

资源截图

代码片段和文件信息

#include “camera.h“
#include “ui_camera.h“
#include 
QTimer *timer2;
camera::camera(QWidget *parent) :
    QWidget(parent)
    ui(new Ui::camera)
{
    ui->setupUi(this);
    timer2 = new QTimer(this);
    connect(timer2 SIGNAL(timeout()) this SLOT(timeSlot()));//连接时间刷新函数
    timer2->start(10);

    /*QString m_fileName=“D:/QT/secretJL/software/SmartMemory/1111.png“;
    QImage img;        //加载图像
    if(!(img.load(m_fileName)))
    {
        QMessageBox::information(this
                                 tr(“打开图像失败“)
                                 tr(“打开图像失败!“));
        return;
    }

    img = img.scaled(ui->label_image->width()ui->label_image->height()Qt::KeepAspectRatio);
    ui->label_image ->setPixmap(QPixmap::fromImage(img));
*/


    my_cam = new QCamera(this);//添加显示界面
    my_cam->setCaptureMode(QCamera::CaptureVideo);//设置摄像头捕获模式
    //my_cam->setViewfinder(ui->widget);//设置取景器
    my_cam->start();//启动摄像头
    QCameraImg = new QCameraImageCapture(my_cam);//截取图像

    Qobject::connect(QCameraImg &QCameraImageCapture::imageCaptured this &camera::displayImage);//触发的信号为


}

void camera::displayImage(int id QImage image)
{
    image = image.scaled(ui->label_image->width()ui->label_image->height()Qt::KeepAspectRatio);
    ui->label_image->setPixmap(QPixmap::fromImage(image));//将捕获的图片映射到label中

    QDateTime qtimeObj = QDateTime::currentDateTime();
    QZXing decode;
    QString str = decode.decodeImage(image);
    if(str.isEmpty()==false){
        ui->lineEdit->setText(str);
        timer2->stop();
        //my_cam->stop();
    }
    else
        ui->lineEdit->setText(tr(“未识别到条形码图片!%1“).arg(qtimeObj.toString(“yyyyMMddhhmmsszzz“)));
}
void camera::on_pushButton_2_clicked()
{
    /*拍照按钮槽*/
    my_cam->start();//启动摄像头
    timer2->start(10);
    QCameraImg->capture();//拍照获取一帧
}
 /*保存照片*/
/*
void camera::on_pushButton_3_clicked()
{

   QCameraImg->capture();//拍照获取一帧
    const QPixmap *pixmap = ui->label_image->pixmap();

    if(pixmap)

    pixmap->save(“D:\\img.png“);

    else

    qDebug()<<“qwe“;
}
*/


camera::~camera()
{
    delete ui;
}
//时间显示回调函数
void camera::timeSlot()
{
    QCameraImg->capture();//拍照获取一帧
}
void camera::on_pushButton_clicked()
{
    QString m_fileName;
    m_fileName = QFileDialog::getOpenFileName(this
                                                 tr(“条形码打开文件“)
                                                 “./“
                                                 tr(“任何文件(*.*)“
                                                    “;;文本文件(*.png)“)
                                                 );
    qDebug()<
       if(m_fileName.isEmpty() == false)
       {
           //ui->statusBar->setToolTip(m_fileName);
           QImage img;        //加载图像
           if(!(img.load(m_fileName)))
           {
               QMessageBox::information(this
                                   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        646  2019-01-06 19:13  secretJL\software\SmartMemory\.qmake.stash

     文件      90540  2019-04-10 10:26  secretJL\software\SmartMemory\1111.png

     文件       3853  2019-04-10 22:59  secretJL\software\SmartMemory\camera.cpp

     文件        651  2019-04-10 17:03  secretJL\software\SmartMemory\camera.h

     文件       3983  2019-04-10 21:14  secretJL\software\SmartMemory\camera.ui

     文件        900  2018-06-12 11:00  secretJL\software\SmartMemory\CustomStandardItemModel.cpp

     文件        432  2018-06-12 11:00  secretJL\software\SmartMemory\CustomStandardItemModel.h

     文件    8176163  2019-01-24 00:44  secretJL\software\SmartMemory\debug\SmartMemory.exe

     文件      20491  2019-03-13 19:47  secretJL\software\SmartMemory\example1.cpp

     文件       1020  2019-03-13 19:48  secretJL\software\SmartMemory\example1.h

     文件       6788  2019-02-18 14:30  secretJL\software\SmartMemory\example1.ui

     文件       1338  2019-03-04 11:06  secretJL\software\SmartMemory\form.cpp

     文件        432  2019-03-04 10:55  secretJL\software\SmartMemory\form.h

     文件       2326  2019-02-20 16:55  secretJL\software\SmartMemory\form.ui

     文件        194  2019-02-20 16:27  secretJL\software\SmartMemory\form1.cpp

     文件        288  2019-02-20 16:55  secretJL\software\SmartMemory\form1.h

     文件      10605  2019-02-20 16:57  secretJL\software\SmartMemory\form1.ui

     文件       4394  2018-06-12 11:00  secretJL\software\SmartMemory\HHeadViewClass.cpp

     文件       1471  2018-06-12 11:00  secretJL\software\SmartMemory\HHeadViewClass.h

     文件   24742912  2019-03-13 19:50  secretJL\software\SmartMemory\jilu.db

     文件        507  2019-04-10 09:00  secretJL\software\SmartMemory\main.cpp

     文件       2796  2019-03-07 23:06  secretJL\software\SmartMemory\mainwindow.cpp

     文件        841  2019-04-10 08:59  secretJL\software\SmartMemory\mainwindow.h

     文件       4738  2019-03-07 21:03  secretJL\software\SmartMemory\mainwindow.ui

     文件      22915  2019-04-10 21:34  secretJL\software\SmartMemory\Makefile

     文件     568936  2019-04-10 21:34  secretJL\software\SmartMemory\Makefile.Debug

     文件     570208  2019-04-10 21:34  secretJL\software\SmartMemory\Makefile.Release

     文件      11203  2019-03-13 19:49  secretJL\software\SmartMemory\menu.cpp

     文件        873  2019-03-11 23:36  secretJL\software\SmartMemory\menu.h

     文件       4670  2019-03-07 23:18  secretJL\software\SmartMemory\menu.ui

............此处省略724个文件信息

评论

共有 条评论