主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506

GitHub:https://github.com/yinghualuowu

上文我们已经让图像变成了很多框框,根据原先版本,这种做法可以使用图形定位,因为车牌有尺寸规定啦,这是原版本的代码,还是别动了。

首先,我们设定一个最小的面积值:2000

先把矩形找到,把面积小的排除了,然后根据长宽比再排除一些,接下来保存合适的就行了

def img_findContours(img_contours,oldimg):
img, contours, hierarchy = cv2.findContours(img_contours, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = [cnt for cnt in contours if cv2.contourArea(cnt) > Min_Area]
print("findContours len = ", len(contours))
# 排除面积最小的点
debug.img_show(img)
car_contours = []
for cnt in contours: ant = cv2.minAreaRect(cnt)
width, height = ant[1]
if width < height:
width, height = height, width
ration = width / height
print(ration)
if ration > 2 and ration < 5.5:
car_contours.append(ant)
box = cv2.boxPoints(ant)
box = np.int0(box)
debug.img_contours(oldimg,box)
return car_contours

会发现圈不全,是因为预处理的原因....以后会用其他方式去定位,我们换一个吧

毕业设计 python opencv实现车牌识别 形状定位-LMLPHP毕业设计 python opencv实现车牌识别 形状定位-LMLPHP

05-11 21:45