#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "tesseract\baseapi.h"
#include "tesseract\strngs.h"
//#include<opencv2\opencv.hpp>
#pragma comment(lib,"libtesseract302.lib")
#pragma comment(lib, "liblept168.lib")
#include <iostream>
#include<opencv/highgui.h>
#include<opencv/cxcore.h>
#include"qmessagebox.h"
#include <stdio.h >
//
using namespace cv;
using namespace std;
#include "chepaishibie.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include<qfiledialog.h>
#include<qtextcodec.h>
#include<qmessagebox.h>
#include <iostream>
#include"qlineedit.h"
void swap1(float *a, float *b);
void swap2(int *a, int *b);
bool isEligible(const RotatedRect &candidate);
void OstuBeresenThreshold(const Mat &in, Mat &out);
Mat getRplane(const Mat &in);
chepaishibie::chepaishibie(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
chepaishibie::~chepaishibie()
{
}
Mat image;//定义读入图像
QImage img;//
string name;//定义图片地址字符串
void chepaishibie::on_pushButton_clicked()//打开图片
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image File(*.bmp *.jpg *.jpeg *.png)"));
QTextCodec *code = QTextCodec::codecForName("gb18030");//转码
name = code->fromUnicode(filename).data();//获取图片地址
image = imread(name);//读取图片
//将图片长缩放为480
if (image.cols < 480)
{
float n = (float)480 / image.cols;
cv::resize(image, image, Size((float)image.cols*n, (float)image.rows*n), 0, 0, CV_INTER_LINEAR);
}
else
{
float n = (float)image.cols / 480;
cv::resize(image, image, Size((float)image.cols / n, (float)image.rows / n), 0, 0, CV_INTER_LINEAR);
}
//提示是否找到图片
if (!image.data)
{
QMessageBox msgBox;
msgBox.setText(tr("image data is null"));
msgBox.exec();
return;
}
else
{
cv::cvtColor(image, image, CV_BGR2RGB);
img = QImage((const unsigned char*)(image.data), image.cols, image.rows, image.cols*image.channels(), QImage::Format_RGB888);
ui.label->clear();
ui.label->setPixmap(QPixmap::fromImage(img));
ui.label->resize(ui.label->pixmap()->size());
}
}
int myOtsu(const IplImage *frame) //大津法求阈值
{
#define GrayScale 256 //frame灰度级
int width = frame->width;
int height = frame->height;
int pixelCount[GrayScale] = { 0 };
float pixelPro[GrayScale] = { 0 };
int i, j, pixelSum = width * height, threshold = 0;
uchar* data = (uchar*)frame->imageData;
//统计每个灰度级中像素的个数
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixelCount[(int)data[i * width + j]]++;
}
}
//计算每个灰度级的像素数目占整幅图像的比例
for (i = 0; i < GrayScale; i++)
{
pixelPro[i] = (float)pixelCount[i] / pixelSum;
}
//遍历灰度级[0,255],寻找合适的threshold
float w0, w1, u0tmp, u1tmp, u0, u1, deltaTmp, deltaMax = 0;
for (i = 0; i < GrayScale; i++)
{
w0 = w1 = u0tmp = u1tmp = u0 = u1 = deltaTmp = 0;
for (j = 0; j < GrayScale; j++)
{
if (j <= i) //背景部分
{
w0 += pixelPro[j];
u0tmp += j * pixelPro[j];
}
else //前景部分
{
w1 += pixelPro[j];
u1tmp += j * pixelPro[j];
}
}
u0 = u0tmp / w0;
u1 = u1tmp / w1;
deltaTmp = (float)(w0 *w1* pow((u0 - u1), 2));
if (deltaTmp > deltaMax)
{
deltaMax = deltaTmp;
threshold = i;
}
}
return threshold;
}
//识别按钮事件
void chepaishibie::on_pushButton_2_clicked()
{
const char* c_s = name.c_str();
IplImage *imgSrc = cvLoadImage(c_s);
Mat mat123 = cvarrToMat(imgSrc);
IplImage *imgH, *imgS, *imgV, *imgHSV, *imgGray;
//通过分离颜色通道,选择蓝色区域为车牌
imgHSV = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 3);
imgH = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 1);
imgS = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 1);
imgV = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 1);
cvCvtColor(imgSrc, imgHSV, CV_BGR2HSV);
cvSplit(imgHSV, imgH, imgS, imgV, 0);
cvInRangeS(imgH, cvScalar(94, 0, 0, 0), cvScalar(115, 0, 0, 0), imgH);
cvInRangeS(imgS, cvScalar(90, 0, 0, 0), cvScalar(255, 0, 0, 0), imgS);
cvInRangeS(imgV, cvScalar(36, 0, 0, 0), cvScalar(255, 0, 0, 0), imgV);
IplImage *imgTemp, *imgHsvBinnary;
imgTemp = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 1);
imgHsvBinnary = cvCreateImage(cvGetSize(imgSrc), imgSrc->depth, 1);
cvAnd(imgH, imgS, imgTemp);
cvAnd(imgTemp, imgV, imgHsvBinnary);
//形态学去噪
//定义结构元素
IplConvKernel *element = 0;
int values[2] = { 255, 255 };
int rows = 2, cols = 1, anchor_x = 0, anchor_y = 1;
element = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, CV_SHAPE_CUSTOM, values);
//膨胀腐蚀
cvDilate(imgHsvBinnary, imgHsvBinnary, element, 1);
cvErode(imgHsvBinnary, imgHsvBinnary, element, 1);
/*cvNamedWindow("imgh1");
cvShowImage("imgh1", imgHsvBinnary);*/
Mat mat12 = cvarrToMat(imgHsvBinnary);
float n = (float)mat12.cols / mat12.rows;
//图片缩放长为1000
cout << "长宽比1" << n << endl;
if (mat12.cols < 1000)
{
float n = (float)1000 / mat12.cols;
cv::resize(mat12, mat12, Size((float)mat12.cols*n, (float)mat12.rows*n), 0, 0, CV_INTER_LINEAR);
}
else
{
float n = (float)mat12.cols / 1000;
cv::resize(mat12, mat12, Size((float)mat12.cols / n, (float)mat12.rows / n), 0, 0, CV_INTER_LINEAR);
}
cout << "长" << mat12.cols << "宽" << mat12.rows << endl;
float n1 = (float)mat12.cols / mat12.rows;
cout << "长宽比1" << n1 << endl;
//resize(mat12, mat12, Size(850, 540), 0, 0, CV_INTER_LINEAR);
//Mat element1 = getStructuringElement(MORPH_RECT, Size(13, 13)); //闭形态学的结构元素
//morphologyEx(mat12, mat12, MORPH_CLOSE, element1);
//中值滤波
medianBlur(mat12, mat12, 3);
//Mat element1 = getStructuringElement(MORPH_RECT, Size(13, 13)); //闭形态学的结构元素
//morphologyEx(mat12, mat12, MORPH_CROSS, element1);
medianBlur(mat12, mat12, 5);
int blockSize = 11;
int constValue = 10;
Mat img_gray;
//adaptiveThreshold(mat12, mat12, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, blockSize, constValue);//自适应二值化
imwrite("1221.jpg", mat12);
Mat r = imread("1221.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat r1 = imread("1221.jpg", 1);
adaptiveThreshold(r, r, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, blockSize, constValue);//自适应二值化
vector <vector< Point> > contours;
//cout <<contours.size() << endl;
vector<Vec4i> hierarchy;
findContours(r, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); //只检测外轮廓对候选的轮廓进行进一步筛选
int index = 0;
//cout << "thy" << contours.size() << endl;
for (; index = 0; index = hierarchy[index][0])
{
Scalar color(rand() & 255, rand() & 200, rand() & 255);
drawContours(r, contours, index, color, FILLED, 8, hierarchy);
}
vector <vector< Point >>::iterator itc = contours.begin();
RotatedRect mr = minAreaRect(Mat(*itc));
vector <RotatedRect> rects;
while (itc != contours.end())
{
RotatedRect mr = minAreaRect(Mat(*itc)); //返回每个轮廓的最小有界矩形区域
if (!isEligible(mr)) //判断矩形轮廓是否符合要求
{
itc = contours.erase(itc);
}
else
{
rects.push_back(mr);
++itc;
}
}
cv::resize(mat123, mat123, Size(mat12.cols, mat12.rows), 0, 0, CV_INTER_LINEAR);
//测试是否找到了号码区域
cout << "qwe" << rects.size() << endl;
Point2f vertices[4];
if (rects.size() == 0){
QMessageBox msgBox2;
msgBox2.setText(tr("don't find the license plate"));
msgBox2.exec();
return;
}
rects[0].points(vertices);
for (int i = 0; i < 4; i++)
line(mat123, vertices[i], vertices[(i + 1) % 4], CV_RGB(0, 0, 255), 3);
imwrite("mat123.jpg", mat123);
Mat matimg = imread("mat123.jpg", 1);
float mat123x = (float)matimg.cols / 2;
float mat123y = (float)matimg.rows / 2;
cv::resize(matimg, matimg, Size(mat123x, mat123y), 0, 0, CV_INTER_LINEAR);
QImage imgcp
没有合适的资源?快使用搜索试试~ 我知道了~
车牌识别opencv+tesseract-ocr
共125个文件
h:66个
dll:17个
tlog:9个
4星 · 超过85%的资源 需积分: 38 206 下载量 150 浏览量
2017-11-27
12:39:44
上传
评论 12
收藏 72.36MB ZIP 举报
温馨提示
车牌识别代码,利用opencv实现对车牌的定位,tesseract-ocr进行车牌的识别。
资源推荐
资源详情
资源评论
收起资源包目录
车牌识别opencv+tesseract-ocr (125个子文件)
chepaishibie.cpp 18KB
main.cpp 319B
chepaishibie.VC.db 1.53MB
opencv_imgproc310d.dll 26.03MB
opencv_imgproc310.dll 19.89MB
opencv_core310d.dll 12MB
opencv_core310.dll 8.72MB
Qt5Guid.dll 8.31MB
Qt5Cored.dll 8.18MB
Qt5Widgetsd.dll 7.74MB
libtesseract302.dll 4.16MB
opencv_imgcodecs310d.dll 4.13MB
liblept168.dll 3.25MB
opencv_imgcodecs310.dll 2.44MB
opencv_video310d.dll 712KB
opencv_videoio310d.dll 484KB
opencv_video310.dll 412KB
opencv_highgui310d.dll 295KB
opencv_videoio310.dll 236KB
opencv_highgui310.dll 136KB
chepaishibie.exe 276KB
chepaishibie.vcxproj.filters 3KB
leptprotos.h 192KB
png.h 119KB
zlib.h 86KB
jpeglib.h 49KB
pngconf.h 47KB
pix.h 43KB
unicharset.h 35KB
tiff.h 33KB
tesscallback.h 32KB
baseapi.h 30KB
genericvector.h 25KB
tiffio.h 20KB
capi.h 16KB
zconf.h 15KB
jerror.h 15KB
pageiterator.h 13KB
jmorecfg.h 13KB
readbarcode.h 11KB
publictypes.h 10KB
environ.h 10KB
params.h 10KB
resultiterator.h 9KB
ltrresultiterator.h 9KB
morph.h 8KB
thresholder.h 8KB
arrayaccess.h 8KB
imageio.h 7KB
jbclass.h 6KB
host.h 6KB
strngs.h 6KB
regutils.h 5KB
helpers.h 5KB
ccbord.h 5KB
array.h 4KB
heap.h 4KB
bmp.h 4KB
errcode.h 3KB
unichar.h 3KB
tiffconf.h 3KB
ptra.h 3KB
unicharmap.h 3KB
dewarp.h 3KB
gplot.h 3KB
watershed.h 3KB
list.h 3KB
queue.h 3KB
sudoku.h 3KB
bmf.h 2KB
stack.h 2KB
bbuffer.h 2KB
platform.h 2KB
memry.h 2KB
tif_config.h 2KB
serialis.h 2KB
alltypes.h 2KB
fileerr.h 1KB
jconfig.h 1KB
apitypes.h 1KB
basedir.h 1KB
leptwin.h 1KB
allheaders.h 1KB
freetype.h 1KB
ndminx.h 1KB
chepaishibie.h 584B
tiffvers.h 410B
endianness.h 205B
chepaishibie.ilk 1.96MB
mat123.jpg 223KB
1221.jpg 25KB
cpy.jpg 24KB
cpz.jpg 7KB
cpzj.jpg 4KB
chepaishibie.lastbuildstate 196B
chepaishibie.log 4KB
chepaishibie.Build.CppClean.log 2KB
chepaishibie.log 831B
chepaishibie.obj 1019KB
moc_chepaishibie.obj 404KB
共 125 条
- 1
- 2
资源评论
- 原来是阿中2018-06-22还没看。。。。。。
- pintime2019-11-05车牌识别opencv+tesseract-ocr
- 贝壳里的沙2018-06-03不知道可以不可以
- a532733081a2018-07-25C++写的,标题没写清楚,不是我想要的
ShuangLi_abc
- 粉丝: 3
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功