camera: transformer un laptop en camera de surveillance pour appartement

This commit is contained in:
2025-08-29 09:09:39 +02:00
commit f3fc2590a7
5 changed files with 65 additions and 0 deletions

33
camera.py Normal file
View 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")