'How to find individual numbers in an image with Python OpenCV?

I have an image similar to the following. I want to separate two numbers 7 and 4 as shown in the image, in that I want to have a bounding box for each of these two objects.

enter image description here

How could I do this with OpenCV? I have no idea, how could I do this and was thinking if there is some way by using Sobel operator. The only thing that I tired was getting the Sobel.

s = cv2.Sobel(img, cv2.CV_64F,1,0,ksize=5)

enter image description here

but have no idea on how to proceed from here.



Solution 1:[1]

Follow the steps:

  1. Convert the image into grayscale.
  2. Use thresholding to convert image into a binary image, in your problem I think adaptive gausian will be most beneficial to use.
  3. Apply contour detection and then you can make bounding box around contours.

You may need to filter contours based on size or position.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community