目前,我正在尝试编写一个程序,该程序可以检测手写数字和诸如log和sin之类的数学单词。但是,目前,在编写程序时,我的程序只能检测到单个符号,因此,即使检测到数字很好,单词也被检测为单独的字母。附件是我当前的代码。
import cv2
import numpy as np
from PIL import Image, ImageOps
img = cv2.imread("example.JPG")
morph = img.copy()
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
morph = cv2.morphologyEx(morph, cv2.MORPH_CLOSE, kernel)
morph = cv2.morphologyEx(morph, cv2.MORPH_OPEN, kernel)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 15))
# take morphological gradient
gradient_image = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel)
gray = cv2.cvtColor(gradient_image, cv2.COLOR_BGR2GRAY)
#take this out?
img_grey = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
# blur = cv2.medianBlur(gray,5)
blur = cv2.medianBlur(img_grey,3)
ret, thing = cv2.threshold(blur, 0.0, 255.0, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
img_dilation = cv2.dilate(thing, kernel, iterations=3)
cv2.imwrite("check_equal.jpg", img_dilation)
conturs_lst = cv2.findContours(img_dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
coor_lst = []
for cnt in conturs_lst:
x,y,w,h = cv2.boundingRect(cnt)
if w < 15 or h < 15:
continue
coor_lst.append((x,y,w,h))
如何将数字的行为保持不变,但又以某种方式允许程序检测到事物是单词,从而在整个单词周围绘制边界框?
答案 0 :(得分:1)
您的问题:
您的选择是:
引用: 多年的计算机视觉研究 https://en.wikipedia.org/wiki/MNIST_database#Dataset