如何在python opencv中获取坐标并使用它们通过arduino的串行端口控制炮塔

时间:2019-04-15 02:08:33

标签: windows opencv arduino-uno python-3.7

我正在尝试让我的Python代码使用Arduino Uno上的串行端口进行连接。问题是我不知道如何获取我得到的X和Y值并将它们关联起来,因此我的炮塔将跟踪它。

我尝试使用面部跟踪中的其他代码,但似乎无法将其覆盖。我知道我想把它变成这样的格式。         xx = int(x +(x + h))/ 2         yy = int(y +(y + w))/ 2

    print (xx)
    print (yy)

    center = (xx,yy)

#Draw Circles
if circles is not None:
        for i,x,y in circles[0,:]:
            # If the ball is close, draw it in green
            if int(round(i[2])) > 35:
                print("Location:", str(int(round(x[0]))), ":", str(int(round(y[1]))))
                cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),int(round(i[2])),(0,255,0),5)
                cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),2,(0,255,0),10)


                output = str(int(round(i[0])))+ str(int(round(i[1])))
                ser.write(output.encode())
            # else draw it in red
            elif int(round(i[2])) < 30:
                cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),int(round(i[2])),(0,0,255),5)
                cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),2,(0,0,255),10)
                buzz = 1


#Show the result in frames
cv2.imshow('HueComp',hthresh)
cv2.imshow('SatComp',sthresh)
cv2.imshow('ValComp',vthresh)
cv2.imshow('closing',closing)
cv2.imshow('tracking',frame)

每次输入的内容都会有不同的错误。诸如语法错误或我未定义之类的东西

0 个答案:

没有答案