I am trying to match a text with opencv and make the background of the provided image white.
import cv2
import numpy as np
img_rgb = cv2.imread('./image/10.jpg')
template = cv2.imread('./image/matchedTxt_106.jpg')
w, h = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = .5
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 0), -1)
cv2.imwrite('result1.png', img_rgb)
Currently, I get the following result:
Find here my google colab example:
I would like to replace the watermark with the following text:
Any suggestions what I am doing wrong? Furthermore how can I get the coordinates of where sub-image is located on this picture?
I appreciate your replies!