Detect both images using cv2 template matching

Viewed 50

I have two images, I'm currently using the first one for template matching. It doesn't match all templates, maybe because in some templates cards are present, in some they are not. How can I use 1 template and match both cases ?

Image I'm using:

Image I'm using

The other image:

The other image

This the an example of input image from which I want to detect this template:

Example:

Example

I don't know much about template matching I am using TM_CCOEFF_NORMED

    match = cv2.matchTemplate(roi, resized_template, cv2.TM_CCOEFF_NORMED)
    
    rows, cols = np.where(match > match_threshold)
    values = match[rows, cols]
    
    for detect_x, detect_y, value in zip(cols, rows, values):
        detections += [(detect_x + roi_x, detect_y + roi_y, template_width, template_height, value)]

When I try matching the template using the first template example and filter by match threshold above 55%, it only matches the first two templates that have cards. When I use the second image as a template example it only matches the last one. I can use both but it slows down the process so I want to know if there's way to ignore the cards while matching but include them in the result. Maybe an image preprocessing method which ignores the cards. I might not even be the cards but I'm guessing it's the cards that are not letting it match.

0 Answers
Related