函数正好接受 4 个参数(给定 2 个)

function takes exactly 4 arguments (2 given)

我正在尝试制作一个矩形并将所有参数传递给该函数,但它不起作用,我也尝试更改代码但它不起作用。

第一次尝试(他不取颜色,粗细和线型)

cv2.rectangle(haystack_img, top_left, bottom_right, color=(0, 255, 0), thickness=2, lineType=cv2.LINE_4)

第二次尝试我之前声明了它们(现在我遇到了参数问题)

cv2.rectangle(haystack_img, top_left, bottom_right, color, thickness, lineType)

完整代码

import cv2
import numpy as np


haystack_img = cv2.imread('screen.jpg', cv2.IMREAD_UNCHANGED)
needle_img = cv2.imread('mr_karate.jpg', cv2.IMREAD_UNCHANGED)

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

min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)

needle_w = needle_img[1]
needle_h = needle_img[0]

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

color = (0, 255, 0)
thickness = 2
lineType = cv2.LINE_4

cv2.rectangle(haystack_img, top_left, bottom_right, color, thickness, lineType)


cv2.imshow('Result', haystack_img)
cv2.waitKey()

我需要帮助,我卡在这上面,我不知道问题出在哪里

bottom_right 值不正确。

(array([[ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       ...,
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255]], dtype=uint8), array([[ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       ...,
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255],
       [ 29,  29,  29, 255]], dtype=uint8))

bottom_right 应该像 (20,20)

bottom_right = (20,20)