Reputation: 157
Currently, I am attempting to write a program that can detect handwritten numbers and mathematical words such as log and sin. However, right now as written my program can only detect individual symbols, so while numbers are being detected just fine, words are detected as separate letters. Attached is my current code.
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))
How would one go about keeping the behavior the same for numbers but somehow allowing the program to detect that things are words are draw bounding boxes around the entire word?
Upvotes: 0
Views: 379
Reputation: 145
Your problem:
Your options are:
Citations: Years of computer vision research https://en.wikipedia.org/wiki/MNIST_database#Dataset
Upvotes: 1