求助
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
ret, frame = cap.read()
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xFF == ord('a'):
cv2.imwrite("camera.jpg",frame)
break
cap.release()
cv2.destroyAllWindows()
cap = cv2.VideoCapture(0)
img = cv2.imread(1)
gray = cv2.imread("C:\Users\Administrator\camera.jpg",0)#这处哥,系统显示说明我的gray这是无效变量
img1 = cv2.imread("C:\Users\Administrator\Desktop\w.png")
img2 = cv2.imread("C:\Users\Administrator\Desktop\s.png")
img3 = cv2.imread("C:\Users\Administrator\Desktop\l.png")
img4 = cv2.imread("C:\Users\Administrator\Desktop\r.png")
img_template1 = cv.imread("C:\Users\Administrator\Desktop\w.png",0)
img_template2 = cv.imread("C:\Users\Administrator\Desktop\s.png",0)
img_template3 = cv.imread("C:\Users\Administrator\Desktop\l.png",0)
img_template4 = cv.imread("C:\Users\Administrator\Desktop\r,png",0)
res1 = cv2.matchtemplate(gray,img_template1,cv2.TM_SQDIFF)
if res1 >= 0.8 :
print("电机向前")
else:
break
res2 = cv2.matchtemplate(gray,img_template2,cv2.TM_SQDIFF)
if res2 >= 0.8:
print("电机向后")
else:
break
res3 = cv2.matchtemplate(gray,img_template3,cv2.TM_SQDIFF)
if res3 >= 0.8:
print("电机向左")
else:
break
res4 = cv2.matchtemplate(gray,img_template3,cv2.TM_SQDIFF)
if res4 >= 0.8:
print("电机向右")
else:
break
各位老哥可以帮我看一下这个程序的错误吗?想了好久,,呜呜呜