2017-02-28 40 views
0

提取信件我有我想要的每一个字符分别提取图像OpenCV的 - 从字符串使用python

enter image description here

正如我想THIS OUTPUT等。

什么是使用OpenCV和python来做到这一点的适当方法?

+0

您已经提供了与sample和output1相同的链接。 – frederick99

+0

@ frederick99对不起..现在请再次检查.... – Bits

回答

1

可以执行下列操作(OpenCV的3.0和aboove)

    图像上
  1. 运行大津的阈值(http://docs.opencv.org/3.2.0/d7/d4d/tutorial_py_thresholding.html
  2. 运行连通区域标记与上阈值的图像的统计数据。(How to use openCV's connected components with stats in python?
  3. 对于每个连接的组件,使用您从步骤2获得的统计数据,为每个共用字体获取以下信息(cv2.CC_STAT_LEFT cv2.CC_STAT_TOP cv2.CC_STAT_WIDTH cv2.CC_STAT_HEIGHT)
  4. Usi边框从原始图像裁剪组件。
0

Amitay的真棒答案的一个补充。你应该使用

cv2.THRESH_BINARY_INV

捕捉到白纸上的黑字否定的形象。

另一个想法可能是MSER斑点检测这样的:

img = cv2.imread('path to image') 
 
(h, w) = img.shape[:2] 
 
image_size = h*w 
 
mser = cv2.MSER_create() 
 
mser.setMaxArea(image_size/2) 
 
mser.setMinArea(10) 
 

 
gray = cv2.cvtColor(filtered, cv2.COLOR_BGR2GRAY) #Converting to GrayScale 
 
_, bw = cv2.threshold(gray, 0.0, 255.0, cv2.THRESH_BINARY | cv2.THRESH_OTSU) 
 

 
regions, rects = mser.detectRegions(bw) 
 

 
# With the rects you can e.g. crop the letters 
 
for (x, y, w, h) in rects: 
 
    cv2.rectangle(img, (x, y), (x+w, y+h), color=(255, 0, 255), thickness=1)

这也导致了一个完整的信认。

enter image description here