擅长:python、mysql、java
<p>谢谢<a href="https://stackoverflow.com/users/6885902/jeru-luke">Jeru Luke</a>,我们可以在一个完整的页面上实现这个尝试。给出的值对于模糊和腐蚀操作中的内核适应非常有帮助。<a href="https://i.stack.imgur.com/ek0GK.jpg" rel="nofollow noreferrer">The final result on the Bible Historiale Manuscript page</a>仍然非常有趣。根据我的理解,在鉴定中我们可以看到一些“黑洞”,这是第一个正在进行的工作。我们必须管理大图片和大写字母。
下面是我们用来过滤框、在框上添加标签以及将每个片段保存在单独文件中的代码:</p>
<pre><code>for i,component in enumerate(zip(contours, hierarchy)):
cnt = component[0]
currentHierarchy = component[1]
if currentHierarchy[2] > 0 and currentHierarchy[3] > 0:
x,y,w,h = cv2.boundingRect(approx)
if h < 300 and h > 110 and w > 110:
cv2.rectangle(im,(x-5,y-5),(x+w+5,y+h+5),(0,255,0),8)
cv2.putText(im,str(i),(x+2,y+2), font, 1,(0,255,0),2,cv2.LINE_AA)
cv2.putText(im,str(cv2.contourArea(cnt)),(x+w-2,y+h-2), font, 1,(0,255,0),2,cv2.LINE_AA)
cv2.putText(im,str(h)+'/'+str(w),(x+w-2,y+h-2), font, 1,(0,0,255),2,cv2.LINE_AA)
fragment = im[y:y+h, x:x+w]
cv2.imwrite("res" + str(i) + ".png", fragment)
</code></pre>