#encoding=utf-8
import cv2
clicked = False
def onMouse(event,x,y,flags,param):
global clicked
if event == cv2.EVENT_LBUTTONUP:
clicked = True
pass
# cameraCapture = cv2.VideoCapture(0)
#USB
cameraCapture = cv2.VideoCapture(0)
cv2.namedWindow('my_window')
cv2.setMouseCallback('my_window',onMouse)
print('showing camera feed.click window or press any key to stop')
success, frame = cameraCapture.read()
while True:
cv2.imshow('my_window',frame)
success, frame = cameraCapture.read()
if success and cv2.waitKey(1) == -1 and not clicked :
pass
else:
file_name = "/home/pi/Desktop/test.jpg"
cv2.imwrite(file_name,frame)
break
pass
cv2.destroyWindow('my_window')
cameraCapture.release()
树莓派使用USB拍摄代码
最新推荐文章于 2024-01-16 14:08:11 发布