I am trying to detect certain COLORED images in a desktop screenshot, where I have equally shaped templates but different color (these are not distinguished from one another doing the normal matchTemplate method as it is done with greyscale images) here is the main code that does the detection:
template = cv2.imread(template_path,1)
#template_hsv = cv2.cvtColor(template, cv2.COLOR_RGB2HSV)
#template_B, template_G, template_R = cv2.split(template)
#scr_B, scr_G, scr_R = cv2.split(screenshot)
scr_B = screenshot[:, :, 0]
scr_G = screenshot[:, :, 1]
scr_R = screenshot[:, :, 2]
template_B = template[:, :, 0]
template_G = template[:, :, 1]
template_R = template[:, :, 2]
#cv2.imwrite('./sc4.png', scr_R)
#cv2.imwrite('./template.png', template)
resB = cv2.matchTemplate(scr_B, template_B, cv2.TM_CCOEFF_NORMED)
resG = cv2.matchTemplate(scr_G, template_G, cv2.TM_CCOEFF_NORMED)
resR = cv2.matchTemplate(scr_R, template_R, cv2.TM_CCOEFF_NORMED)
res = resB + resG + resR
#res = cv2.matchTemplate(screenshot, template_G, cv2.TM_CCOEFF_NORMED)
matches = np.where(res >= 3*threshold)
print(matches)
return matches
As you can see I tried splitting the channels of the rgb screenshot image, and compare then with the also splitted template image. I also tried doing this with HSV channels as you can see in the commented code. However this did not work and despite seeing that in single channeled images there was a visual difference of color, the program did not distinguish them (I also tried doing comparisons with each individual channel of the template and screenshot) .
All sugestions are welcome, even trying to achieve my goal using anything else. Thank you in advance.