我的if语句出现错误。我已经检查了缩进。一切看起来都很好,但是我仍然无法消除错误。
PS-在这段代码之前还有一个if语句和while语句。
#pointer on video
M = cv.moments(cnt)
if(M['m00']!=0):
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv.circle(frame, (cx,cy,4,(0,255,0),-1)
# Cursor Motion
if cx < 150:
dist_x = -20
elif cx > 250:
dist_x = 20
else:
dist_x = 0
if cy < 150:
dist_y = -20
elif cy > 250:
dist_y = 20
else
dist_y = 0
pyautogui.moveRel(dist_x,dist_y,duration=0.25)