camera: transformer un laptop en camera de surveillance pour appartement
This commit is contained in:
33
camera.py
Normal file
33
camera.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Python program to capture a single image
|
||||
# using pygame library
|
||||
|
||||
# importing the pygame library
|
||||
import pygame
|
||||
import pygame.camera
|
||||
import time
|
||||
|
||||
# initializing the camera
|
||||
pygame.camera.init()
|
||||
|
||||
# make the list of all available cameras
|
||||
camlist = pygame.camera.list_cameras()
|
||||
|
||||
# if camera is detected or not
|
||||
if camlist:
|
||||
|
||||
# initializing the cam variable with default camera
|
||||
cam = pygame.camera.Camera(camlist[0], (640, 480))
|
||||
|
||||
# opening the camera
|
||||
cam.start()
|
||||
time.sleep(10)
|
||||
|
||||
# capturing the single image
|
||||
image = cam.get_image()
|
||||
|
||||
# saving the image
|
||||
pygame.image.save(image, "filename.jpg")
|
||||
|
||||
# if camera is not detected the moving to else part
|
||||
else:
|
||||
print("No camera on current device")
|
||||
Reference in New Issue
Block a user