commit f3fc2590a72a3f2cf36026805ea9cbca674f2fe6 Author: Thomas lavocat Date: Fri Aug 29 09:09:39 2025 +0200 camera: transformer un laptop en camera de surveillance pour appartement diff --git a/GeeksForGeeks.png b/GeeksForGeeks.png new file mode 100644 index 0000000..27e2d5d Binary files /dev/null and b/GeeksForGeeks.png differ diff --git a/camera.py b/camera.py new file mode 100644 index 0000000..08ed9ed --- /dev/null +++ b/camera.py @@ -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") diff --git a/camera2.py b/camera2.py new file mode 100644 index 0000000..822a409 --- /dev/null +++ b/camera2.py @@ -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") + diff --git a/filename.jpg b/filename.jpg new file mode 100644 index 0000000..caa0e09 Binary files /dev/null and b/filename.jpg differ diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..6a0e598 --- /dev/null +++ b/script.sh @@ -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