Android+Opencv+Tesseract-ocr识别不同底色的车牌,蓝色,绿色(新能源)车牌

本文介绍了如何使用Android平台结合OpenCV库和Tesseract OCR技术,针对不同底色(蓝色和绿色新能源车牌)进行精确识别。步骤包括屏幕区域提取、车牌区域定位、二值化处理和字符识别,展示了关键代码片段。

视频效果:https://www.bilibili.com/video/BV1fK4y137ky
上图:
在这里插入图片描述
在这里插入图片描述
项目介绍:Android+Opencv+Tesseract-ocr识别不同底色的车牌,蓝色,绿色(新能源)车牌

项目步骤:
1、提取屏幕区域
2、提取车牌区域
3、二值化车牌图片
4、Tesseract-ocr识别字符

直接上代码:
想看的再跟我说,后续再详细些写


public class PlateDetector {
   
   
    private static String TAG="PlateDetector";

    //浅蓝0、//黄色1、//品红2、//浅红色3、//蓝色4、//青色5、// 深红色6、//黑色7      车牌蓝底9  车牌绿底10
    public static double[][] HSV_VALUE_LOW = {
   
   
            {
   
   10,163,147},//浅蓝0
            {
   
   77, 163, 147},//黄色1
            {
   
   146, 212, 140},//品红2
            {
   
   126,155, 160},//浅红色3
            {
   
   0, 204, 178},//蓝色4
            {
   
   35, 163, 147},//青色5
            {
   
   110,155,160},// 深红色6
            {
   
   0,0,0},//黑色7
            {
   
   0,0,192},//标准蓝8
            {
   
   0,190,190},//车牌蓝底9      暗的TFT:0,190,190   亮的:0,180,190
            {
   
   22,195,158}//车牌绿底10    暗的TFT H:21 S要调高一点:210  V:211  亮的TFT S值要调底一点:110    10,100,148
    };

    public static double[][] HSV_VALUE_HIGH = {
   
   
            {
   
   47,255,255},//浅蓝0
            {
   
   111, 255,255},//黄色1
            {
   
   241, 255, 255.0},//品红2
            {
   
   150,255, 255},//浅红色3
            {
   
   21, 255, 255},//蓝色4
            {
   
   75, 255.0, 255},//青色5
            {
   
   150,255,255},// 深红色6
            {
   
   180,255,120},//黑色7
            {
   
   45,238,255},//标准蓝8
            {
   
   28,255,255},//车牌蓝底9   亮暗一样
            {
   
   73,255,255}//车牌绿底10   暗H:66     亮H:83
    };
    public String plateDetector(Bitmap bitmap){
   
   

        String plateStr=null;

        Mat mRgba=Bitmap2Mat(bitmap);
        /**
         * ***********************车牌识别**************
         */
        //实现步骤1、直接HSV颜色空间裁剪出来车牌,计算长宽比来过滤掉
        //实现步骤2、阈值分割,边缘检测,检测完之后绘制填充
        //实现步骤3、填充之后二值化,二值化之后保存下来训练
//        show_bitmap(mRgba);//显示图片到View

        Mat gray=new Mat();
        Imgproc.cvtColor(mRgba,gray,Imgproc.COLOR_BGR2GRAY);//灰度化

        Mat binary=new Mat();
        Imgproc.Canny(gray,binary,50,150);//二值化  边缘检测

        Mat kernel=Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size(3,3));//  指定腐蚀膨胀核
        Imgproc.dilate(binary,binary,kernel);
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
        Mat hierarchy=new Mat();
        Imgproc.findContours(binary, contours, hierarchy,
                Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);//查找轮廓

        double maxArea = 0;
        Iterator<MatOfPoint> each = contours.iterator();
        while (each.hasNext()) {
   
   
            MatOfPoint wrapper = each.next();
            double area = Imgproc.contourArea(wrapper);
            if (area > maxArea) {
   
   
                maxArea = area;
            }
        }
        Mat result=null;
        each = contours.iterator();
        while (each.hasNext()) {
   
   
            MatOfPoint contour = each.next();
            double area = Imgproc.contourArea(contour);
            if (area > 0.01 * maxArea) {
   
   
                // 多边形逼近 会使原图放大4倍
                Core.multiply(contour, new Scalar(4, 4), contour);
                MatOfPoint2f newcoutour = new MatOfPoint2f(contour.toArray());
                MatOfPoint2f resultcoutour = new MatOfPoint2f();
                double length = Imgproc.arcLength(newcoutour, true);
                Double epsilon = 0.01 * length;
                Imgproc.approxPolyDP(newcoutour, resultcoutour, epsilon, true);
                contour = new MatOfPoint(resultcoutour.toArray());
                // 进行修正,缩小4倍改变联通区域大小
                MatOfPoint new_contour=new MatOfPoint();
                new_contour=ChangeSize(contour);
                double new_area = Imgproc.contourArea(new_contour);//轮廓的面积
                // 求取中心点
                Moments mm = Imgproc.moments(contour);
                int center_x = (int) (mm.get_m10() / (mm.get_m00()));
                int center_y = (int) (mm.get_m01() / (mm.get_m00()));
                Point center = new Point(center_x, center_y);

                //最小外接矩形
                Rect re
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值