Mohamed Thasin ah
Mohamed Thasin ah

Reputation: 11192

Character segmentation not working for 3,8

I'm new to image processing. I want to perform character segmentation in OCR. I have already done necessary pre-processing. When I perform character segmentation by finding contouring it works well except for the character 3, 8.

After pre processed image looks like this,

pre processed image

Output after finding contouring for 3 and 8 is

enter image description here

enter image description here

Code used:

imgGray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
ret, imgThresh = cv2.threshold(imgGray, 127, 255, 0)
image, contours , _ = cv2.findContours(imgThresh, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

But it gives good result for other characters:

enter image description here

enter image description here

enter image description here

How to solve this issue?

Upvotes: 0

Views: 143

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

Since your image does not involve any complex background I used Otsu's method to pick the right threshold for me:

threshold, thresh_img = cv2.threshold(imgGray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

enter image description here

Now when you find contours it will be easier. That is because contours are found for objects or charaters that are in white.

enter image description here

Have a look at those characters that caused problems now:

enter image description here

enter image description here

Upvotes: 4

Related Questions