TypeError: Scalar value for argument 'color' is not numeric

Viewed 654
import cv2 as cv
import numpy as np
import os

os.chdir(os.path.dirname(os.path.abspath(__file__)))

haystack_img = cv.imread('osrs_iron_rock.png', cv.IMREAD_UNCHANGED)
needle_img = cv.imread('osrs_dwarven_mine.png', cv.IMREAD_UNCHANGED)

result = cv.matchTemplate(haystack_img, needle_img, cv.TM_SQDIFF_NORMED)


threshold = 0.17
locations = np.where(result <= threshold)

if locations:
    print('Found needle')

    needle_w = needle_img.shape[1]
    needle_h = needle_img.shape[0]
    line_color = (0, 255, 0)
    line_type = cv.LINE_4

    for loc in locations:

        top_left = loc
        bottom_right = (top_left[0] + needle_w, top_left[1] + needle_h)

        cv.rectangle(haystack_img, top_left, bottom_right, line_color, line_type)

        cv.imshow('matches', haystack_img)
        cv.waitKey()

else:
    print('no needle found')

Running this code gives me an error:

"TypeError: Scalar value for argument 'color' is not numeric"

I have tried using such strategies such as using int(x) for x in line_color to replace line_color in the command but to no avail.

0 Answers
Related