【发布时间】:2019-02-20 10:49:06
【问题描述】:
我正在尝试构建用于从图像中提取文本的 OCR,我正在使用轮廓来形成文本字符的边界,
经过几次更改 cv2.threshold 的试验后,我在形成文本字符边界时获得了最适合的轮廓。
#files = os.listdir(r'letters/harry.jpeg',0)
file = r'/home/naga/Documents/Naga/Machine Learning/Data_extract/letters/Harry/Harry Potter and the Sorcerer s Stone-page-006.jpg'
im1 = cv2.imread(file,0)
im = cv2.imread(file)
# ret,thresh1 = cv2.threshold(im1,180,278,cv2.THRESH_BINARY)
# _,contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
ret,thresh1 = cv2.threshold(im1,180,278,cv2.THRESH_BINARY)
kernel = np.ones((5,5),np.uint8)
dilated = cv2.dilate(im1,kernel,iterations = 1)
_,contours, hierarchy = cv2.findContours(dilated,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
#bound the images
cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),1)
cv2.namedWindow('BindingBox', cv2.WINDOW_NORMAL)
cv2.imwrite('output2/BindingBox4.jpg',im)
现在我想在单词上创建轮廓。我需要每个单词的父轮廓。 Open cv中要更改的属性是什么。
我是 opencv 的新手,我关注了cv2 threshold,但无法理解如何应用它。请提供您的输入以形成单词的轮廓。
【问题讨论】:
标签: python opencv ocr tesseract opencv-contour