我正在制作车牌识别应用程序。我设法找到了每个板块元素的轮廓。我如何裁剪它们,调整大小和组合,这样tesseract ocr才能完成它的工作,并识别车牌上的文本。为了更清楚,我附上了文章中的图片。
发布于 2018-12-10 00:39:52
这是非常直接的。找到轮廓,循环通过轮廓,找到每个轮廓的边界矩形,裁剪出零件,调整裁剪零件的大小,并将它们存储在列表中。然后,您可以迭代新列表,并使用numpy的hstack
连接它们。我已经分享了完整的代码,但是你需要一些过滤技术来删除多余的轮廓,所以要小心。
代码:
import cv2
import numpy as np
img = cv2.imread('1.png',0)
image, contours, hierarchy = cv2.findContours(img.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
boxes = list()
cropped_imageList = list()
for c in contours:
#if you want to store the original coordinates
x,y,w,h = cv2.boundingRect(c)
boxes.append((x,y,w,h))
#crop out the part of the image and resize
crop_img = img[y:y+h, x:x+w]
crop_img = cv2.resize(crop_img,(50,50))
cropped_imageList.append(crop_img)
#join them back
imstack = cropped_imageList[0]
for imgs in cropped_imageList[1:]:
imstack = np.hstack((imstack,imgs))
注意:这将随机连接找到的字母,解决此问题的一种方法是使用x,y
对boxes
列表进行排序,然后进行裁剪。
当tesseract可以直接检测到文本时,你为什么要这么做呢?如果你想要更好的结果,你应该使用深度学习的现代方法。
https://stackoverflow.com/questions/53694083
复制相似问题