其实功能需求很简单,就是能够打开一张带有车牌的图片,检测出车牌的位置。
我的程序架构是: Qt作为交互界面->Opencv作为处理内核
先放一份没有进行算法优化,没有SVM的效果和代码,等回去有时间再放比较准确的代码。
#include "qt1.h"
#include <qapplication.h>
#include<QMessageBox>
#include<qfiledialog.h>
#include<qimage.h>
#include<qpixmap.h>
#include<qfileinfo.h>
#include<qscrollarea.h>
#include<qgridlayout.h>
#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include "opencv2/highgui/highgui.hpp"
#include"stdio.h"
#include"iostream"
using namespace std;
using namespace cv;
//函数声明
float roi_white(Mat &img, int x, int y, int length, int width);//感兴趣区域检测白色概率
void sharpen(Mat &image, Mat &result);//图像锐化
void raise(Mat &);//提高图片亮度以及对比度
void black(Mat &, Mat &);
void paint(Mat &img);
int scale = 1;
int delta = 0;
int ddepth = CV_16S;//图像的深度,为了防止溢出
RNG rng(12345);
char file[100];
QImage Mat2QImage(cv::Mat cvImg);
qt1::qt1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void qt1::button()
{
QString filename;
filename = QFileDialog::getOpenFileName(this, tr("Select image:"),//用对话框获取目标地址
"1", tr("Images (*.png *.bmp *.jpg *.gif)"));
if (filename.isEmpty()) {
return;
}
QImage image;
if (!image.load(filename)) {
QMessageBox::information(this, tr("Error"), tr("Open file error"));
return;
}
setWindowTitle(tr(" Car detection"));
string str;
str = filename.toStdString();
filename = QString::fromStdString(str);//把string转换为Qstring
Mat img = imread(str);
paint(img);
int img_height, img_width;
img_height = ui.label->height();
img_width = ui.label->width();
cv::resize(img, img, Size(img_width, img_height));
image = Mat2QImage(img);
/*QImage *imgScaled = new QImage;
*imgScaled = image.scaled(200, 200, Qt::KeepAspectRatio);//设置大小
*/
QPixmap pixmap = QPixmap::fromImage(image);
QSize imageSize = pixmap.size();
ui.label->setPixmap(pixmap);//绘图在label上
ui.label->res