最近在弄车牌识别这个项目,对于机器视觉有些了解的人都知道,这个东西算是比较成熟了,在书里也有代码。
网上能找到的资料也比较多,所及借着这个机会在ARM开发板上实现以下车牌识别。
反正对于神经网络这些什么的我是不知道了,所以代码也是网上借鉴了的,我稍微整理注释了下。
先放下移植opencv的步骤:移植opencv到嵌入式arm详细过程
第一步做的就是车牌提取:
代码如下:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <string>
#include <cvaux.h>
#include <stdio.h>
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/ml/ml.hpp>
using namespace cv;
using namespace std;
//车牌宽高比为520/110=4.727272左右,误差不超过40%
//车牌高度范围在15~125之间,视摄像头距离而定(图像大小)
bool verifySizes_closeImg(const RotatedRect & candidate)
{
float error = 0.4;//误差40%
const float aspect = 4.7272;//44/14; //长宽比
int min = 15*aspect*15;//20*aspect*20; //面积下限,最小区域
int max = 125*aspect*125;//180*aspect*180; //面积上限,最大区域
float rmin = aspect - aspect*error; //考虑误差后的最小长宽比
float rmax = aspect + aspect*error; //考虑误差后的最大长宽比
int area = candidate.size.height * candidate.size.width;//计算面积
float r = (float)candidate.size.width/(float)candidate.size.height;//计算宽高比
if(r <1)
r = 1/r;
if( (area < min || area > max) || (r< rmin || r > rmax) )//满足条件才认为是车牌候选区域
return false;
else
return true;
}
void RgbConvToGray(const Mat& inputImage,Mat & outpuImage) //g = 0.3R+0.59G+0.11B
{
outpuImage = Mat(inputImage.rows ,inputImage.cols ,CV_8UC1);
for (int i = 0 ;i<inputImage.rows ;++ i)
{
uchar *ptrGray = outpuImage.ptr<uchar>(i);
const Vec3b * ptrRgb = inputImage.ptr<Vec3b>(i);
for (int j = 0 ;j<inputImage.cols ;++ j)
{
p