Локализация номерного знака.
Я работаю над проектом по распознаванию номерного знака. При локализации пластины я сначала беру все прямоугольные контуры, а затем выбираю из них самый большой контур.
for img in images:
gray_image_array = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grayscale
resized = imutils.resize(gray_image_array, width=300)
ratio = gray_image_array.shape[0] / float(resized.shape[0])
#gray_image_mf = median_filter(gray_image_array, 1) #applying unsharp mask filter
ret,thresh1 = cv2.threshold(gray_image_array,150,255,cv2.THRESH_BINARY) #thresholding
thresh1 = cv2.bitwise_not(thresh1)
#......applying canny edge detection....
v = np.median(thresh1)
sigma=0.33
lower = int(max(0, (1.0 - sigma) * v))
upper = int(min(255, (1.0 + sigma) * v))
edges = cv2.Canny(thresh1,100,200)
#...canny ends......
#.......applying dilation.....
kernel = np.ones((5,5),np.uint8)
dilation = cv2.dilate(edges,kernel,iterations = 2)
closing = cv2.morphologyEx(dilation, cv2.MORPH_CLOSE, kernel)
#.........dilation ends.......
contours, hierarchy = cv2.findContours(closing.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#im = cv2.drawContours(closing,contours,-1,(255,0,0),5)
h,w,_ = img.shape
mask = np.zeros((h+2,w+2), np.uint8)
for c in contours:
poly = cv2.approxPolyDP(c, 0.02*cv2.arcLength(c,True),True)
if len(poly) == 4:
# if the contour has 4 vertices then floodfill that contour with black color
co = max(c, key = cv2.contourArea)
cnt = np.vstack(co).squeeze()
ret,closing,mask,_ = cv2.floodFill(closing, mask, tuple(cnt[0]), 0)
plt.imshow(closing,cmap="gray")
plt.show()
Получение ошибки
<ipython-input-17-4161649b8e06> in <module>
co = max(c, key = cv2.contourArea)
cnt = np.vstack(co).squeeze()
---> ret,closing,mask,_ = cv2.floodFill(closing, mask, tuple(cnt[0]), 0)
plt.imshow(closing,cmap="gray")
одно из моих изображений