美文网首页
【车牌识别】part1先设计个“好看”的界面

【车牌识别】part1先设计个“好看”的界面

作者: llooRice | 来源:发表于2017-11-24 15:11 被阅读0次

用c++写界面,用MFC库和Qt库的比较多。Qt相比MFC而言,更加的简易,更加容易上手,所以博主选择了用Qt写界面(其实是我MFC太生疏了,逃。。。)

首先得装上个Qt,就Qt5.8好了,我选择了MSVC版本的,因为我要在VS上调用Qt。另外下载qs-vs-tools工具,装好之后,稍加配置,就可以愉快地写代码了。VS配合Qt使用,美滋滋。。。

下面是我设计的界面,觉得怎么样呢?是不是一股浓重的乡村重金属风格的画风迎面而来。。。哈哈,不管了,先将就弄成这样,以后再更改。


界面

下面贴出代码,代码很简单。
NumIdentify.h

#pragma once
#pragma execution_character_set("utf-8")
#include <QtWidgets/QDialog>
#include <ImageProcessor.h>
//#include "ui_NumIdentify.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qprogressbar.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <qgraphicsview.h>

class NumIdentify : public QDialog
{
    Q_OBJECT

public:
    NumIdentify(QWidget *parent = Q_NULLPTR);

private:
    //Ui::NumIdentifyClass ui;
    QLabel *ImageLabel1;
    QLabel *ImageLabel2;
    QLabel *TextLabel;
    QLabel *StatusLabel;

    QPushButton *OpenBtn;
    QPushButton *CleanBtn;
    QPushButton *IdentifyBtn;

    QGraphicsView *Image1;
    QGraphicsView *Image2;

    QProgressBar *Progress;

    QTextEdit *TextShow;

    //the followings are layout
    QVBoxLayout *LeftLayout;
    QVBoxLayout *RightLayout;
    QHBoxLayout *TopLayout;
    QHBoxLayout *BottomLayout;
    QVBoxLayout *MainLayout;

    //two scenes
    QGraphicsScene *scene1;
    QGraphicsScene *scene2;

    //一个ImageProcessor类的指针
    ImageProcessor *i=NULL;

public:
    void showImage(QImage img,uint view)const;//this function 
    void init();

private slots:
    void onOpenFile();
    void onClean();
    void onIdentify();
};

NumIdentify.cpp

#include "NumIdentify.h"
#include <qgraphicsscene.h>
#include <qpixmap.h>
#include <ImageProcessor.h>
#include <qfiledialog.h>
#include <qmessagebox.h>
#include <qfont.h>

NumIdentify::NumIdentify(QWidget *parent)
    : QDialog(parent)
{
    //ui.setupUi(this);
    this->setGeometry(50, 50, 1200,500);
    init();//this function can create the ui

}

//INIT finish arranging layout and appearance
void NumIdentify::init()
{
    //create widgets and add them into layout
    //the Top Left Layout
    ImageLabel1 = new QLabel(tr("Original Image"));
    scene1 = new QGraphicsScene;
    Image1 = new QGraphicsView(scene1);

    LeftLayout = new QVBoxLayout;

    LeftLayout->addWidget(ImageLabel1);
    LeftLayout->addWidget(Image1);
    LeftLayout->setAlignment(Qt::AlignCenter);

    //set the right layout
    ImageLabel2 = new QLabel(tr("Cut Image"));
    scene2 = new QGraphicsScene;
    Image2 = new QGraphicsView(scene2);
    //
    TextLabel = new QLabel(tr("Identified Text"));
    TextShow = new QTextEdit();
    RightLayout = new QVBoxLayout;
    RightLayout->addWidget(ImageLabel2);
    RightLayout->addWidget(Image2);
    RightLayout->addWidget(TextShow);
    RightLayout->setAlignment(Qt::AlignCenter);

    //set the bottom layout
    OpenBtn = new QPushButton(tr("Open File"));
    CleanBtn = new QPushButton(tr("Clean"));
    IdentifyBtn = new QPushButton(tr("Identify"));
    StatusLabel = new QLabel("Status:");
    Progress = new QProgressBar;
    BottomLayout = new QHBoxLayout;
    BottomLayout->addWidget(OpenBtn);
    BottomLayout->addWidget(CleanBtn);
    BottomLayout->addWidget(IdentifyBtn);
    BottomLayout->addWidget(StatusLabel);
    BottomLayout->addWidget(Progress);

    //set the top layout
    TopLayout = new QHBoxLayout;
    TopLayout->addLayout(LeftLayout);
    TopLayout->addLayout(RightLayout);

    //set the general layout
    MainLayout = new QVBoxLayout(this);
    MainLayout->addLayout(TopLayout);
    MainLayout->addLayout(BottomLayout);
    setLayout(MainLayout);

    //上面的语句完成了UI的初始化
    //以下语句将控件和函数联系起来,主要是一些connect函数
    connect(OpenBtn, SIGNAL(clicked()), this, SLOT(onOpenFile()));
    connect(CleanBtn, SIGNAL(clicked()), this, SLOT(onClean()));
    connect(IdentifyBtn, SIGNAL(clicked()), this, SLOT(onIdentify()));
}

//SHOWIMAGE show image designated view
//when view=0,show image in scene1
//when view=1,show image in scene2
//this function must be used after scene1 and scene2 were created.
void NumIdentify::showImage(QImage img, uint view)const
{
    QPixmap temp = QPixmap::fromImage(img,Qt::ColorOnly);
    if (view == 0)
    {
        scene1->addPixmap(temp);
    }
    else if (view == 1)
    {
        scene2->addPixmap(temp);
    }
}

void NumIdentify::onOpenFile()
{
    QString path0 = QFileDialog::getOpenFileName(this, tr("Open..."), tr("D:\\"), tr("Images (*.jpg *.jpeg)"));
    if (path0.length() == 0) {
        QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
        return;//退出
    }
    string path = path0.toStdString();//QString to string
    i = new ImageProcessor(path);
    
    //显示原始图形
    showImage(i->Mat2QImage(i->originalImage), 0);
}

void NumIdentify::onIdentify()
{
    if (i != NULL)//存在ImagegProcessor对象才能识别啊
    {
        i->action();
    }
    else if (i == NULL)
    {
        return;
    }
    //显示切割图像accurateImage
    //Mat temp;
    //cvtColor(i->accurateImage, temp, CV_GRAY2BGR);
    showImage(i->Mat2QImage(i->accurateImage), 1);

    //显示切割出来的字符
    string tmp="";
    for (int k = 0; k < i->recognizedCharacters.size(); k++)
        tmp = tmp + i->recognizedCharacters[k];

    QString tmp1 = QString::fromStdString(tmp);
    TextShow->setFontWeight(QFont::Bold);//粗体显示
    TextShow->setFont(QFont("Timers", 28, QFont::Bold));
    TextShow->setPlainText(tmp1.toUtf8());
}

void NumIdentify::onClean()
{
    //QMessageBox::information(this, tr("just try"), tr("test"));
    //先把所有的显示给清空
    scene1->clear();
    scene2->clear();
    TextShow->clear();
    i = NULL;
}

完毕

相关文章

  • 【车牌识别】part1先设计个“好看”的界面

    用c++写界面,用MFC库和Qt库的比较多。Qt相比MFC而言,更加的简易,更加容易上手,所以博主选择了用Qt写界...

  • 技术解析:移动端前端车牌识别OCR算法

    核心技术:移动车牌识别技术,ios车牌识别,车牌识别技术移动端,移动端车牌识别技术,手机端车牌识别,OCR车牌识别...

  • 可以手持的车牌识别技术-移动端车牌识别

    核心技术:移动车牌识别技术,ios车牌识别,车牌识别技术移动端,移动端车牌识别技术,手机端车牌识别,OCR车牌识别...

  • 智慧停车与车牌识别技术

    核心技术:移动车牌识别技术,ios车牌识别,车牌识别技术移动端,移动端车牌识别技术,手机端车牌识别,OCR车牌识别...

  • 车牌识别技术的前世今生

    手机也能用的移动端车牌识别技术 核心技术:移动车牌识别技术,ios车牌识别,车牌识别技术移动端,移动端车牌识别技术...

  • 2019-11-30

    手机也能用的移动端车牌识别技术 核心技术:移动车牌识别技术,ios车牌识别,车牌识别技术移动端,移动端车牌识别技术...

  • 车牌识别技术优势

    1、车牌识别技术率高,识别速度快:车牌识别率高达98%,识别速度小于0.5秒 2、车牌识别技术车牌可识别车牌种类多...

  • 二、车牌识别技术优势

    车牌识别技术率高,识别速度快:车牌识别率高达98%,识别速度小于0.5秒 2、车牌识别技术车牌可识别车牌种类多:手...

  • 车牌识别技术优势

    1、车牌识别技术率高,识别速度快:车牌识别率高达98%,识别速度小于0.5秒 2、车牌识别技术车牌可识别车牌种类多...

  • 车牌识别系统车牌识别算法车牌识别

    车牌识别系统车牌识别算法车牌识别 一套完整的车牌识别系统包含车牌识别一体机、停车场收费显示屏、智能道闸、车牌识别软...

网友评论

      本文标题:【车牌识别】part1先设计个“好看”的界面

      本文链接:https://www.haomeiwen.com/subject/eqoxbxtx.html