基於python+opencv的車牌號碼識別
車牌識別行業已具備一定的市場規模,在電子警察、公路卡口、停車場、商業管理、汽修服務等領域已取得了部分應用。乙個典型的車輛牌照識別系統一般包括以下4個部分:車輛影象獲取、車牌定位、車牌字元分割和車牌字元識別
1、車牌定位的主要工作是從獲取的車輛影象中找到汽車牌照所在位置,並把車牌從該區域中準確地分割出來
這裡所採用的是利用車牌的顏色(黃色、藍色、綠色) 來進行定位
#定位車牌
def color_position
(img,output_path)
: colors =[(
[26,43
,46],
[34,255
,255])
, # 黃色([
100,43,
46],[
124,
255,
255]
), # 藍色([
35,43,
46],[
77,255,
255]
) # 綠色
]hsv = cv2.
cvtcolor
(img, cv2.
color_bgr2hsv
)for
(lower, upper)
in colors:
lower = np.
array
(lower, dtype=
"uint8"
) # 顏色下限
upper = np.
array
(upper, dtype=
"uint8"
) # 顏色上限
# 根據閾值找到對應的顏色
mask = cv2.
inrange
(hsv, lowerb=lower, upperb=upper)
output = cv2.
bitwise_and
(img, img, mask=mask)
k =mark_zone_color
(output,output_path)
if k==1:
return
1 # 展示
2、將車牌提取出來
def mark_zone_color
(src_img,output_img)
: #根據顏色在原始影象上標記
#轉灰度
gray = cv2.
cvtcolor
(src_img,cv2.
color_bgr2gray
) #影象二值化
ret,binary = cv2.
threshold
(gray,0,
255,cv2.
thresh_binary
) #輪廓檢測
x,contours,hierarchy = cv2.
findcontours
(binary,cv2.
retr_tree
,cv2.
) #drawing = img
#cv2.
drawcontours
(drawing, contours,-1
,(0,
0,255),3
) # 填充輪廓顏色
#cv2.
imshow
('drawing'
, drawing)
#cv2.
waitkey(0
)#print
(contours)
temp_contours =
# 儲存合理的輪廓
car_plates=
iflen
(contours)
>0:
for contour in contours:
if cv2.
contourarea
(contour)
> min_area:
temp_contours.
(contour)
car_plates =
for temp_contour in temp_contours:
rect_tupple = cv2.
minarearect
(temp_contour)
rect_width, rect_height = rect_tupple[1]
if rect_width < rect_height:
rect_width, rect_height = rect_height, rect_width
aspect_ratio = rect_width / rect_height
# 車牌正常情況下寬高比在2
-5.5之間
if aspect_ratio >
2 and aspect_ratio <
5.5:
car_plates.
(temp_contour)
rect_vertices = cv2.
boxpoints
(rect_tupple)
rect_vertices = np.
int0
(rect_vertices)
iflen
(car_plates)==1
: oldimg = cv2.
drawcontours
(img,
[rect_vertices],-
1,(0
,0,255),
2)#cv2.
imshow
("che pai ding wei"
, oldimg)
# print
(rect_tupple)
break
#把車牌號擷取出來
基於Python OpenCV的單目標輪廓匹配
python opencv 實現單目標餐盤輪廓識別 import cv2 import numpy as np def template template temp cv2.imread template,0 temp gray cv2.cvtcolor temp,cv2.color bgr2gra...
python opencv 基於SSD的人臉檢測
ssd ssd是一種基於深度學習的目標檢測演算法,opencv在3.3版本以後將其引入作為基於深度學習的人臉檢測器 opencv實現的ssd人臉檢測器的骨幹網路是resnet 10,當前它提供了兩個訓練好的模型 基於深度學習框架caffe訓練的模型和基於tensorflow訓練的模型 face de...
Python Opencv的環境配置
安裝好anaconda後,我們利用anaconda建立虛擬環境 接下來,我們將在cmd中進行操作 在cmd中輸入 condarc系統會自動開啟condarc檔案 然後執行conda clean i清楚快取 換源完成 在cmd中輸入以下 後回車 conda create n py27test pyth...