Opencv:裁剪6位数的手写邮政编码

时间:2019-10-21 05:31:33

标签: python opencv handwriting-recognition number-recognition

我正在尝试为邮政编码分类应用程序裁剪6位手写的邮政编码,给定的代码可以与10位电话号码配合使用,但不能识别6位轮廓。 请更正给定的代码或提供更好的替代代码以完成上述任务。

import numpy as np
import cv2
import imutils


image = cv2.imread("pin5.jpg")
image = imutils.resize(image, width=500)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7, 7), 0)


ret,thresh1 = cv2.threshold(gray ,127,255,cv2.THRESH_BINARY_INV)


dilate = cv2.dilate(thresh1, None, iterations=2)


cnts = cv2.findContours(dilate.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] 
orig = image.copy()
i = 0

for cnt in cnts:

    if(cv2.contourArea(cnt) < 80):
        continue


    x,y,w,h = cv2.boundingRect(cnt)


    roi = image[y:y+h, x:x+w]


    cv2.rectangle(orig,(x,y),(x+w,y+h),(0,255,0),2)

    cv2.imwrite("roi" + str(i) + ".png", roi)

    i = i + 1

cv2.imshow("Image", orig)
cv2.waitKey(0)

0 个答案:

没有答案