opencv 车牌识别

#include<opencv2\opencv.hpp>

#include<iostream> using namespace cv; using namespace std; int areas;

//该函数用来验证是否是我们想要的区域,车牌定位原理其实就是在图片上寻找矩形,我们可以用长宽比例以及面积来验证是否是我们想要的矩形,宽高比为520/110=4.7272 (车牌的长除以宽),区域面积最小为15个像素,最大为125个像素

bool VerifySize(RotatedRect candidate) {     float error = 0.4; //40%的误差范围

    float aspect = 4.7272;//宽高比例

    int min = 25 * aspect * 25; //最小像素为15

    int max = 125 * aspect * 125;//最大像素为125

    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; } int main(int argc, char** argv) {

    Mat src;

    src = imread("D:\\Car1.jpg");//读取含车牌的图片

    if (!src.data)     {

        cout << "Could not open Car.jph.." << endl;

        return -1;

    }

    Mat img_gray;

    cvtColor(src, img_gray, CV_BGR2GRAY);//灰度转换

    Mat img_blur;

    blur(img_gray, img_blur, Size(5, 5));//用来降噪

    Mat img_sobel;

    Sobel(img_gray, img_sobel, CV_8U, 1, 0, 3);//Sobel滤波,对x进行求导,就是强调y方向,对y进行求导,就是强调x方向,在此我们对x求导,查找图片中的竖直边

    Mat img_threshold;

    threshold(img_sobel, img_threshold, 0, 255, THRESH_BINARY | THRESH_OTSU);

    Mat element = getStructuringElement(MORPH_RECT, Size(21, 5));//这个Size很重要!!不同的图片适应不同的Size,待会在下面放图,大家就知道区别了

    morphologyEx(img_threshold, img_threshold,MORPH_CLOSE,element);//闭操作,就是先膨胀后腐蚀,目的就是将图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值