above

With the development of the industry, the market for a variety of needs, the market for license plate recognition system (license plate recognition system) demand is more and more widely, today xiaobian with you to do a simple license plate recognition system small procedures!!

The body of the

The development tools

**Python version: **3.6.4

Related modules:

Cv2 module;

Numpy module.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

Introduction of the principle

Note that this is not license plate recognition, it is license plate detection.

Because the shape of the license plate is relatively simple, I realized it by referring to some simple traditional algorithms without using deep learning. The effect is more general. It is not suitable for license plate detection in complex environment.

Direct tuning of OpenCV function interface, not from 0 to achieve, so the overall technical content is low.

The process is as follows:

Step1:

Image pretreatment, including grayscale, Gaussian smoothing, median filtering, Sobel operator edge detection and so on.

Step2:

OpenCV is used to find the profile of the preprocessed image, and then judge whether the profile is the license plate profile according to some parameters.

Using the demonstration

Run the detect.py file in a CMD window.

Please specify the image path to be detected before using:

​​

The effect is as follows:

1. The original image

2. The artwork:

Effect:

The picture can not be put up !!!!!!​​​

​​​

3. The original image:

Effect:

The picture can not be put up !!!!!!​​​

Attached code:

File: Charles import cv2 import numpy as np # GaussianBlur(img, (3, 3), 0, 0, cv2.border_default) # Median filter = cv2.medianblur (Gaussian, 5) # Sobel operator # gradient direction: X sobel = cv2.sobel (median, cv2.cv_8u, 1, 0, ksize=3) # ret, binary = cv2.threshold(sobel, 170, 255, median, cv2.cv_8u, 1, 0, ksize=3) # ret, binary = cv2.threshold(sobel, 170, 255, 0) Cv2. # THRESH_BINARY) kernel function element1 = cv2. GetStructuringElement (cv2 MORPH_RECT, (9, 1) element2 = cv2. GetStructuringElement (cv2 MORPH_RECT, (9, 7)) # expansion dilation = cv2. Dilate (binary, element2. Iterations =1) # erosion = cv2. Iterations (erodes, element1, iterations=1) # erosion = cv2. iterations=3) return dilation2 def GetRegion(img): Hierarchy = cv2.findContours(img, cv2.retr_tree, cv2.CHAIN_APPROX_SIMPLE) for contour in contours: area = cv2.contourArea(contour) if (area < 2000): continue eps = 1e-3 * cv2.arcLength(contour, True) approx = cv2.approxPolyDP(contour, eps, True) rect = cv2.minAreaRect(contour) box = cv2.boxPoints(rect) box = np.int0(box) height = abs(box[0][1] - box[2][1]) Width = abs(box[0][0] -box [2][0]) ratio =float(width)/float(height) if (ratio < 5 and ratio > 1.8): regions.append(box) return regions def detect(img): # gray = cv2.cvtcolor (img, cv2.COLOR_BGR2GRAY) prc = Process(gray) regions = GetRegion(prc) print('[INFO]:Detect %d license plates' % len(regions))  for box in regions: cv2.drawContours(img, [box], 0, (0, 255, 0), 2) cv2.imshow('Result', img) cv2.imwrite('result.jpg', img) cv2.waitKey(0) cv2.destroyAllWindows()Copy the code

At the end

Well, that’s all for this article

License plate detection and license plate recognition is actually very mature technology. So what I’m doing is rookie level.

A casual look at the code to try to write, need to complete the project source 🎆🎆 add group [959755565] can receive free oh!!