Character cutting of license plate Recognition 2

Source: Internet
Author: User
cutting on a vertical projectionFirst, I choose the license plate number as a projection of the picture, can be used as a license plate cutting technology. Principle: After the license plate is processed, all pixel values are stored in an array, then the pixel values of each column are traversed on the x-axis, and the total projected effect is presented in the form of a projection graph, and the gap between the peaks and troughs of the projection graph is the difference between the accumulated pixel values of each column. If this technique is used as a technique for plate character cutting, then the cumulative value of each column pixel is the basis for judging the character area and the blank area.
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <iostream> using
namespace CV;
using namespace Std;
    Vector<mat> Verticalprojectionmat (Mat Image)//Vertical Projection {int perpixelvalue;//value of each pixel int width = image.cols;
    int height = image.rows;
    printf ("High%d of pictures with a width of%d", width, height);  int* Projectvalarry = new int[width];//creates an array to store the number of white pixels per column memset (projectvalarry, 0, Width * 4);//initialize array for (int col = 0; Col < width; col++)//column {for (int row = 0; row < height; row++)//Line {Perpixelvalue = Image.at&lt ;uchar> (Row, col);//The value of each pixel//if (Perpixelvalue = = 0)//If it is black on white if (perpixelvalue = = 255)//If it is black Bottom White (Overlay on projectvalarry[col]++;//column}}} Mat Verticalprojectionma T (height, width, cv_8u, Scalar (255));//Vertical projection of the canvas for (int i = 0; i < height; i++) {for (int j = 0; J & Lt Width
     J + +)   {perpixelvalue = 255;
        The background is set to white verticalprojectionmat.at<uchar> (i, j) = Perpixelvalue;
        }} for (int i = 0; i < width; i++)//Vertical projection histogram {for (int j = 0; J < Projectvalarry[i]; j + +)  {perpixelvalue = 0;
        The histogram is set to black verticalprojectionmat.at<uchar> (Height-1-J, i) = Perpixelvalue;
    }} imshow ("Vertical projection", verticalprojectionmat);//The above is how to make this canvas formed rect rect (0, 0, 356, 90);
    Mat Image_cut = Mat (Verticalprojectionmat, rect);
    Mat image_copy = Image_cut.clone ();

    Imshow ("Cut Picture", image_copy);  
    Vector<mat> roilist;//is used to store each character separated by int startIndex = 0;//record enters the character area of the index int endIndex = 0;//record into the empty area of the index BOOL Inblock = false;//whether to traverse the character area within for (int i = 0; i < image.cols; i++)//cols=width {if (!inblock
            && projectvalarry[i]! = 0)//Enter the character area {Inblock = true;
        StartIndex = i;
     }   else if (projectvalarry[i] = = 0 && inblock)//Enter blank area {endIndex = i;
            Inblock = false;
            Mat roiimg = Image (range (0, image.rows), Range (StartIndex, EndIndex + 1));
        Roilist.push_back (ROIIMG);
    }} delete[] Projectvalarry;
return roilist;
    } int main () {Mat Image = imread ("d://opencv//Practice applet//pictures//image//00a.jpg");
    Imshow ("original", Image);
    Mat Image1;
    Cvtcolor (Image, Image1, Cv_bgr2gray);
    Imshow ("grayscale", Image1);
    Mat Image2;
    Threshold (Image1, Image2, 255, cv_thresh_binary);//Two value of Imshow ("binary", Image2);
    Mat Image3;
    Mat element = Getstructuringelement (Morph_rect, Size (3, 3));

    Morphologyex (Image2, Image3, morph_open, Element);//Open Operation Imshow ("Open operation", Image3);
    Char szname[30] = {0};

        Vector<mat> B = Verticalprojectionmat (Image3);//vertical projection, and cutting/*for (int j = 0; J <b.size (); j + +) {
        sprintf (SzName, "Vertical_%d.jpg", j); ImShow (SzName, B[j]);
    }*/waitkey (0);
return 0; }

(a) Effect diagram
1, the original height is 118, cutting height is 102

2, cutting height is 90

3, the above shows the cutting picture is the ideal to reach the trough, as the character cut the demarcation area, but the light with this cut the picture is not feasible, but the following said can achieve with the same purpose. (ii) finding the trough

The ideal trough can be defined by changing the critical condition in the red box.

When the critical condition is that the pixel cumulative value for each column is 18 o'clock, the effect graph is as follows

(iii) Summary
The main point of the character cutting through vertical projection is to find the exact trough of the character interval, and the Chinese characters with radicals in this experiment are not accurately cut in the middle of Chinese characters. In this method, if the trough of the character interval does not have consistency, or the license plate image processing is not careful enough and difficult to cut accurately.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.