Home > other >  Python control laptop camera photograph
Python control laptop camera photograph

Time:09-18

The import cv2

Def take_picture () :
# for camera video capture
Cap=cv2. VideoCapture (0)
# given initial values to picture filename
I=1
# loop shoot
While True:
# read camera content
Ret, frame=cap. The read ()
# with a window shows the original video
Cv2. Imshow (" Optical Imaging System, frame)
# and keyboard control keys
K=cv2. WaitKey (1)
# get picture filename
File_name=STR (I) + 'JPG'
# features a: press the return key take photos and send
If k==13:
Cv2. Imwrite (file_name, frame)
I=I + 1
Function of # 2: press the esc key to exit the
Elif k==27:
Break
# release USB camera
Cap. Release ()
# close shot window
Cv2. DestroyAllWindows ()

If __name__=="__main__" :
main()
  • Related