TypeError:integer参数预期int在opencv圈子中浮动

问题描述 投票:0回答:1

我已经使用opencv制作了一个手势鼠标控制器,但是当我运行代码时,我在cv2.circle上收到此错误...

Traceback (most recent call last):
File "C:/Users/Arne/PycharmProjects/JARVISv2/Virtual.py", line 65, in <module>
cv2.circle(img, (cx, cy), (w + h) / 4, (0, 0, 255), 2)
TypeError: integer argument expected, got float
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) 
SourceReaderCB::~SourceReaderCB terminating async callback

Process finished with exit code 1

[请有人帮我,我离完成我的项目有点近了非常感谢这是我的代码-

    if (len(conts) == 2):
    if (pinchFlag == 1):
        pinchFlag = 0
        mouse.release(Button.left)
    x1, y1, w1, h1 = cv2.boundingRect(conts[0])
    x2, y2, w2, h2 = cv2.boundingRect(conts[1])
    cv2.rectangle(img, (x1, y1), (x1 + w1, y1 + h1), (255, 0, 0), 2)
    cv2.rectangle(img, (x2, y2), (x2 + w2, y2 + h2), (255, 0, 0), 2)
    cx1 = int(x1 + w1 // 2

)cy1 = int(y1 + h1 // 2)cx2 = int(x2 + w2 // 2)cy2 = int(y2 + h2 // 2)cx =(cx1 + cx2)/ 2cy =(cy1 + cy2)/ 2cv2.line(img,(cx1,cy1),(cx2,cy2),(255,0,0),2)cv2.circle(img,(cx,cy),2,(0,0,255),2)mouseLoc =(sx-(cx * sx / camx),cy * sy / camy)mouse.position = mouseLoc而mouse.position!= mouseLoc:通过

opencv opencv3.0 opencv-contour opencv-python
1个回答
0
投票

您需要为cv2.line和cv2.circle()提供整数坐标。将cx和cy更改为int(cx1)和int(cy1)或仅将int(cx1,cy1)更改为cx2和cy2。或除以2时,使用//而不是/进行除法,以创建整数值。

© www.soinside.com 2019 - 2024. All rights reserved.