Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character segmentation in python

I am working on detecting handwritten symbols using computer vision in python. I trained a cnn on a dataset of individual characters, but now I want to be able to extract characters from an image in order to make predictions on the individual characters. What is the best way to do this? The handwritten text that I will be working with will not be cursive and there will be an obvious separation between the characters.

like image 357
mmmmo Avatar asked Jul 04 '26 21:07

mmmmo


1 Answers

In the below snippet,the boxes variable has dimensions for each character in the image.

import cv2
import pytesseract

file = '/content/Captchas/image22.jpg'

img = cv2.imread(file)
h, w, _ = img.shape

boxes = pytesseract.image_to_boxes(img)

for b in boxes.splitlines():
    b = b.split(' ')
    img = cv2.rectangle(img, (int(b[1]), h - int(b[2])), (int(b[3]), h - int(b[4])), (0, 255, 0), 2)

cv2_imshow(img)
print(boxes)
like image 58
Gokulnath Avatar answered Jul 07 '26 13:07

Gokulnath