# Text detection and recognition from Image

Let say you are given this image and want to detect and recognize the digits printed on the fuses.

for all CV-operations i used OpenCV 3.4.4 and Python I did already these things:

Detection:

1) Thresholding + Canny (using OpenCV 3.4.4): -> Best thresholding result i could achieve was by using Binary or adaptive-gaussian. Here is the result:

As you can see two didigt are really clear segmented out but the remaining are mixed wihth the edges of the fuse.

2) My second attmept was just using Canny-Edge-Detector

The result is somehow better, but still not really perfect.

Recognition

Here i tried to just feed the tesseract with the above images, but the output was horrible. Not even one digit was recognized.

Any suggestion, hint or link is welcome, to get the digits detected and recognized correctly.

Here is my code right now: import cv2 import numpy as np

def canny_threshold(val):
global im_gray, im
im_tmp = im_gray.copy()
low_thresh = cv2.getTrackbarPos("Min Thresh", "main")
max_thresh = cv2.getTrackbarPos("Max Thresh", "main")
im_edges = cv2.Canny(im_tmp, low_thresh, low_thresh * 3)
cv2.imshow("main", dst)

lower_range = np.array([0, 0, 110])
upper_range = np.array([180, 115, 255])

# convert color and cull out of range colors
#im_hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)

# successor functions need a gray image, create it here
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im_gray = cv2.GaussianBlur(im_gray, (9, 9), 0)

# We know the position of the first fuse and the difference between them
# calculate a mask and apply it to the gray image
nx = 60
ny = 55
block_init_pos = [256, 117]
block_diff_x = 510
block_diff_y = 260
for i in range(0, 2):
for j in range(0, 3):
if (i * 4) + j == 12:
continue
idx_x = block_init_pos[0] + block_diff_x * i
idx_y = block_init_pos[1] + block_diff_y * j
mask[idx_y - ny: idx_y + ny, idx_x - nx: idx_x + nx] = 255

# apply mask to the image
ret, im_gray = cv2.threshold(im_gray, 120, 255, cv2.THRESH_BINARY)