2021-01-07 python opencv realizes license plate recognition color positioning

Python opencv realizes license plate recognition color positioning

 

The main code reference https://blog.csdn.net/wzh191920/article/details/79589506

GitHub:https://github.com/yinghualuowu

We found that some pictures are simply positioned randomly because the preprocessing is not done well. If we don’t want to move the preprocessing code, we will change the method.

This is the approximate range of yellow and blue that I have been looking for for a long time

lower_blue = np.array([100, 110, 110])
upper_blue = np.array([130, 255, 255])
lower_yellow = np.array([15, 55, 55])
upper_yellow = np.array([50, 255, 255])

Filter the color~

hsv = cv2.cvtColor(filename, cv2.COLOR_BGR2HSV)
mask_blue = cv2.inRange(hsv, lower_blue, upper_blue)
mask_yellow = cv2.inRange(hsv, lower_yellow, upper_yellow)
output = cv2.bitwise_and(hsv, hsv, mask=mask_blue+mask_yellow)
# 根据阈值找到对应颜色
output = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)

It feels good, at least one can be seen.

Let’s do a little pre-processing opening and closing operation to paste the white area into one piece, hahahaha, it’s ok

Matrix = np.ones((20, 20), np.uint8)
img_edge1 = cv2.morphologyEx(output, cv2.MORPH_CLOSE, Matrix)
img_edge2 = cv2.morphologyEx(img_edge1, cv2.MORPH_OPEN, Matrix)

Then use it to find the rectangle~~~ I found it

 Don't look for cars with similar colors to the license plate! ! ! ! ! !

 

Guess you like

Origin blog.csdn.net/qingfengxd1/article/details/112307202