def process_letter(thresh,output):
# assign the kernel size
kernel = np.ones((2,1), np.uint8) # vertical
# use closing morph operation then erode to narrow the image
temp_img = cv2.morphologyEx(thresh,cv2.MORPH_CLOSE,kernel,iterations=3)
# temp_img = cv2.erode(thresh,kernel,iterations=2)
letter_img = cv2.erode(temp_img,kernel,iterations=1)
# find contours
(contours, _) = cv2.findContours(letter_img.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
# loop in all the contour areas
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
cv2.rectangle(output,(x-1,y-5),(x+w,y+h),(0,255,0),1)
return output
#processing letter by letter boxing
评论列表
文章目录