How do I detect bubble letter numbers

32
November 13, 2019, at 6:00 PM

How should I process and then find the number out of this image:

Here is my code that I use to process the image:

def process_img(screen):
    global filename
    ap = argparse.ArgumentParser()
    ap.add_argument("-p", "--preprocess", type=str, default="thresh",
                    help="type of preprocessing to be done")
    args = vars(ap.parse_args())
    b = screen.copy()
    resizedimg = cv2.resize(b, (750,500))
    gamma = 0.3  # change the value here to get different result
    adjusted = adjust_gamma(resizedimg, gamma=gamma)
    ret, thresh = cv2.threshold(adjusted, 127, 255, cv2.THRESH_BINARY)
    kernel = np.ones((3, 3), np.uint8)
    img = cv2.erode(thresh, kernel, iterations=1)
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    if args["preprocess"] == "thresh":
        img_gray = cv2.threshold(img_gray, 0, 255,
                             cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
    elif args["preprocess"] == "blur":
        img_gray = cv2.medianBlur(img_gray, 3)
    blurred = cv2.GaussianBlur(img_gray, (5, 5), 0)
    edged = cv2.Canny(blurred, 50, 200, 255)
    filename = "{}.png".format(os.getpid())
    cv2.imwrite(filename, blurred)
    return blurred

Which this processes it to: Then I use this code to actually convert the image to text:

text = pytesseract.image_to_string(Image.open(filename), lang='eng', config='--psm 13 --oem 3 -c '
                                                                                'tessedit_char_whitelist=0123456789')

However, this doesn't work most of the time, even when I tried adjusting the settings and making it so only the edges of the text were blurred/smoothed slightly. I wasn't able to smooth it a lot though, if someone has a suggestion to do that, it would be greatly appreciated.

READ ALSO
Is it possible to call a Python DoFn from a Java ParDo in Apache Beam?

Is it possible to call a Python DoFn from a Java ParDo in Apache Beam?

Suppose I'm building a Beam pipeline in Java that will run on a DataflowRunnerIs it possible to call a Python DoFn from a Java ParDo? (or to use a Python PTransform in such a setting?) If this functionality doesn't exist out-of-the-box, what would it take to implement...

12
Positive and Negative Regex in Python

Positive and Negative Regex in Python

I've been using RegEx expressions in Python for a while and I want to find out if it possible to ask RegEx to match a line that has a value in the line but also does not have a value in the same line:

44
Whenever I try using tensorboard I get no module found error

Whenever I try using tensorboard I get no module found error

When I run the command tensorboard --logdir runs --hostlocalhost on my windows I get an error like this ModuleNotFoundError: No module named 'tensorboardmain'; 'tensorboard' is not a package

16
how to generate tensorflow matrix with first of few columns as 1 and the rest as 0

how to generate tensorflow matrix with first of few columns as 1 and the rest as 0

Given a list len_list of the number of ones for the vectors, eg

50