簡體   English   中英

function 正好需要 4 個 arguments(給定 2 個)

[英]function takes exactly 4 arguments (2 given)

我正在嘗試制作一個矩形,並將所有 arguments 傳遞給 function 但它不起作用,我也嘗試更改代碼但它不起作用。

第一次嘗試(他不拿顏色、粗細和線型)

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM