I have .jpg files that contain text and tables (these can be well-readable files, they can be scanned files). On this file I draw a red figure (255, 0, 0), which connects the keywords.
Next, I need to remove all the text, tables, etc., but leave only the drawn red figure (so that I can later compare it with the template. But this is not the issue here.)
I studied the main points that people use to remove unnecessary text. The code is as follows:
import cv2
import numpy as np
img = cv2.imread('file_with_Searching_figure.jpg')
lower = np.array([0, 0, 0])
upper = np.array([20, 20, 255])
thresh = cv2.inRange(img, lower, upper)
# Change non-red to white
result = img.copy()
result[thresh != 255] = (255, 255, 255)
cv2.imwrite('result.jpg', result)
However, the problem is that depending on the quality/content of the file, all unnecessary information (text, tables, etc.) is not completely removed (there are files where it is completely removed – and this is good, but there are files where text only becomes dimmer)
And I would like to get only a red figure in the resulting file and nothing extra. Tell me how to do this correctly