OpenCV cv2.circle“无法解析‘中心’”错误

kok*_*nci 1 python macos opencv apple-m1

我尝试用以下方法画一个圆圈cv2.circle

import cv2

cap = cv2.VideoCapture(0)
while(True):
    ret, frame = cap.read()
    a = cv2.circle(frame, frame[0]/2, frame[1]/2, 30, (0,255,255))
    #cv2.imshow("test", opening)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

运行上面的代码后,我得到了:

 a = cv2.circle(frame, frame[0]/2, frame[1]/2, 30, (0,255,255))
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
>  - Can't parse 'center'. Expected sequence length 2, got 1280
>  - Can't parse 'center'. Expected sequence length 2, got 1280
Run Code Online (Sandbox Code Playgroud)

我认为这是关于中心坐标的,并更改frame[0]/2300,并对其他进行相同的操作。有效。 这是输出。

frame[0]/2所以我使用虚拟机用和测试相同的代码frame[1]/2并做了相同的事情。我收到此错误消息:

a = cv2.circle(frame, tuple(frame[0]/2), tuple(frame[1]/2), 10, (0,255,255))
TypeError: function takes exactly 2 arguments (1920 given)
Run Code Online (Sandbox Code Playgroud)

我的电脑:MacBook pro m1 Visual Studio Code

虚拟机:Ubuntu 20.04.2 LTS PyCharm

谁能帮我?我是 mac、StackOverflow 和 OpenCV 的新手,所以如果我做错了,请指出。谢谢大家。

MWD*_*WDE 6

总的来说,我也遇到了同样的问题。据我所知,这个错误可能源于 4.5.2 版本,我已经解决了这个问题,如下所示:

代替

cv.circle(img,(pts1[1][0],pts1[1][1]),5,(0,0,255),cv.FILLED)

把这个

cv.circle(img,(int(pts1[1][0]),int(pts1[1][1])),5,(0,0,255),cv.FILLED)