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

BIN
GeeksForGeeks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

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")

24
camera2.py Normal file
View File

@@ -0,0 +1,24 @@
# program to capture single image from webcam in python
# importing OpenCV library
import cv2
# initialize the camera
# If you have multiple camera connected with
# current device, assign a value in cam_port
# variable according to that
cam_port = 0
cam = cv2.VideoCapture(cam_port)
# reading the input using the camera
result, image = cam.read()
# If image will detected without any error,
# show result
if result:
# saving image in local storage
cv2.imwrite("GeeksForGeeks.png", image)
# If captured image is corrupted, moving to else part
else:
print("No image detected. Please! try again")

BIN
filename.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

8
script.sh Executable file
View File

@@ -0,0 +1,8 @@
cd /home/tlavocat/dev/camera
while :
do
source .venv/bin/activate
python3 camera.py
curl -u 'thomas:)eCi;@R;dFaH9qr' -T filename.jpg https://nextcloud.chaussette.sale/remote.php/dav/files/thomas/Monitoring/$(date '+%Y-%m-%d_%H:%M:%S').jpg
sleep 5m
done