图像中的轮廓字符,车牌号OpenC

2024-05-29 05:43:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我用python下的opencv读取汽车牌照 下面的代码运行良好

_,thresh = cv2.threshold(Cropped,70,255,cv2.THRESH_BINARY_INV)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
dilated = cv2.dilate(thresh,kernel,iterations = 0)
contoursX, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

(contoursX, boundingBoxes) = contours.sort_contours(contoursX, method="left-to-right")
for contour in contoursX:
    [x,y,w,h] = cv2.boundingRect(contour)
    cv2.rectangle(Cropped, (x, y), (x + w, y + h), (90, 0, 255), 2)
    plt.imshow(Cropped, cmap="gray", vmin=0, vmax=255)
    plt.show()

如您所见,我已经对图像进行了灰度处理,并对其进行了crope,代码中的图像是Cropped

这个代码对我很有用

enter image description here

但是,在某些情况下,轮廓出现错误,如下图所示: enter image description here

原始图片(在croping和灰度之后):

enter image description here

我应该改变轮廓函数中的attributus方法,还是玩颜色

我也在想,也许可以做一些聚类算法作为k-均值聚类黑鬼,但不知道如何或是否会工作。你知道吗

任何帮助:D

编辑 原始第一图像 enter image description here

原始第二图像

enter image description here


Tags: 代码图像plt聚类cv2kernelopencv汽车

热门问题