<p>我继续我的方法来找出单个单词。虽然不完全准确,但请看下图:</p>
<p><a href="https://i.stack.imgur.com/A16jR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A16jR.jpg" alt="enter image description here"/></a></p>
<p>伪代码:</p>
<ol>
<li>对灰度图像应用高斯模糊。在</li>
<li>执行大津阈值。在</li>
<li><p>做了几个形态学手术:</p>
<p>3.1腐蚀-试图去除图像左上方的细线。在</p>
<p>3.2将因上一次操作而分离的单个字母进行扩展。</p></li>
<li><p>找到某个区域上方的轮廓并标记它们</p></li>
</ol>
<p><em>编辑</em></p>
<p>代码:</p>
<pre><code>import numpy as np
import cv2
import matplotlib.pyplot as plt
font = cv2.FONT_HERSHEY_SIMPLEX
im = cv2.imread('corpus.png')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
image_blurred = cv2.GaussianBlur(imgray, (9, 9), 0)
cv2.imshow('blur', image_blurred)
image_blurred_d = cv2.dilate(image_blurred, None)
cv2.imshow('dilated_blur', image_blurred_d)
ret,thresh = cv2.threshold(image_blurred_d, 127, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
cv2.imshow('thresh', thresh)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))
erosion = cv2.erode(thresh, kernel, iterations = 1)
cv2.imshow('erosion', erosion)
kernel1 = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
dilation = cv2.dilate(erosion, kernel1, iterations = 1)
cv2.imshow('dilation', dilation)
_, contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
count = 0
for cnt in contours:
if (cv2.contourArea(cnt) > 100):
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(im, (x,y), (x+w,y+h), (0, 255, 0), 2)
count+=1
print('Number of probable words', count)
cv2.imshow('final', im)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code></pre>