detect text in image and put an image on it

asked 2016-11-25 13:53:26 -0600

sansat gravatar image

updated 2016-11-25 17:11:22 -0600

berak gravatar image

hello i'm beginner in opencv development i wanna get the emplacement of a text like "Helloworld" on a lot of images and get the position to put an image on every text on image without fault.

this is what i made for now with threshold 0.5 but sometimes it's mistake and give me just one emplacement of the code.

def get_box(input_img, input_template, threshold):
img_slicer = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
ccnorm = cv2.matchTemplate(img_slicer, input_template, cv2.TM_CCOEFF_NORMED)
loc = np.where(ccnorm == ccnorm.max())
tw, th = template.shape[::-1]
if ccnorm[zip(*loc[::-1])[0][::-1]] < threshold:
     return None, [0,0]
else:
    (_, maxVal, _, maxLoc) = cv2.minMaxLoc(ccnorm)
    (startX, startY) = (2 * int(maxLoc[0]), 2 * int(maxLoc[1]))
    (endX, endY) = (2 * int((maxLoc[0] +  tw) ), 2 * int((maxLoc[1] +  th)))
    sub_face = input_img[startY:endY, startX:endX]
    return cv2.GaussianBlur(sub_face,(23, 23), 30), [startY, startX]
edit retag flag offensive close merge delete

Comments

can you fix your indentation ?

berak gravatar imageberak ( 2016-11-26 06:04:13 -0600 )edit

the probleme is not in indentation

sansat gravatar imagesansat ( 2016-11-30 11:21:13 -0600 )edit

yea, not for you, ofc. - just for anyone trying to reproduce your problem

berak gravatar imageberak ( 2016-11-30 11:33:38 -0600 )edit

thanks brother, i think there is no one have a solution for this

sansat gravatar imagesansat ( 2016-11-30 11:34:39 -0600 )edit