Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect handwritten characters bounded by a box with OpenCV

I am trying to read a handwritten form which has boxed-input.

Boxed Input

I have run tesseract on the image but get strange results. In my understanding, I suppose the best thing to do is to detect the bounding box and minus that from the image. What's the best way to detect the box (semi-box around the character). I tried cv2.HoughLines(), but with no result.

I am new to OpenCV. It will be really helpful if someone can help me out here.

like image 733
Phani Arava Avatar asked Dec 10 '25 21:12

Phani Arava


1 Answers

Thanks for your idea. I just realized probably i can look at counting the vertical pixels and greater than certain threshold

def get_pixel_count_in_col(img,col):
        count=0
        for j in range(img.shape[0]):
                if(img[j,col]<255):
                        count=count+1
        return count
def cleanup_img(img):
        foundlines=[]
        for i in range(img.shape[1]):
                if(get_pixel_count_in_col(img,i)>img.shape[0]*0.7):
                        foundlines.append(i)
                        if(get_pixel_count_in_col(img,i-1)>img.shape[0]*0.25):
                                foundlines.append(i-1)
                        if(get_pixel_count_in_col(img,i+1)>img.shape[0]*0.25):
                                foundlines.append(i+1)
        return np.delete(img,foundlines,1)

The resulting image makes more sense. But is there any other easy way to do this ?

enter image description here

like image 158
Phani Arava Avatar answered Dec 12 '25 15:12

Phani Arava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!