Replies: 1 comment
-
Hi, I just realize picamera2 is most likely not a good lib for a security cam... Somethin like Hans |
Beta Was this translation helpful? Give feedback.
-
Hi, I just realize picamera2 is most likely not a good lib for a security cam... Somethin like Hans |
Beta Was this translation helpful? Give feedback.
-
Dear all,
just switching from the old picamera to the new picamera2 interface due to whole system upgrade (lite-OS) and a new HQ camera on my (older) RPi 3b. However: I'm not a good prgrammer and have some issues with Python, or at least the latest interface...
I do want to have some kind of custom security camera, motion is detected by some radar sensor connected to GPIO. Doing motion detection vie the RPi would be nice, but isn't needed at all. Better use the CPU/GPU ressources for other tasks. However: the radar sensor kicks in quite late, therefore I do want to have some seconds before the trigger, resulting in the usage of a circular buffer. In overall the RPi should
a) record seamlingless video in highest possible solution
b) stream a Full HD video
c) if a trigger is recognized, take pictures every second in full resolution
Please see my code below, which I created for testing and having some questions:
Any help is highly appreciated. Thanks and best,
Hans
`
#!/usr/bin/python3
script could be run as daemon/service, see below for a short how-to manage it with actual systemd
is a mandatory parameter and should be Pforte_Zuweg or Eingangstuer
/usr/bin/python3 /home/pi/Tfw17_rpicamera/Tfw17_rpicamera.py
import os
import sys
from picamera2 import MappedArray, Picamera2
from picamera2.encoders import H264Encoder, Quality
from picamera2.outputs import CircularOutput, FileOutput
Transform is needed for horizontal/vertical flipping
from libcamera import Transform, controls
cv2 is needed to put some timestamps in the video and pictures
import cv2
import time
from datetime import datetime as dt
from time import sleep
import io
import logging
import socketserver
from threading import Condition
from http import server
# have a try statement to capture some basic failures
#try:
# some debug message
logging.info ('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
logging.info ('^ script for the %s camera/sensor has started right now ^', location)
logging.info ('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
# define a simple Webpage which is used for displaying the (mjpeg-)stream in a browser
#PAGE="""<html><title>stream from camera: """+location+"""</title>"""
# set image/video parameters used for all recordings
#cam_config_still = camera.create_still_configuration(transform=Transform(hflip=True))
#cam_config_video = camera.create_video_configuration(transform=Transform(hflip=True))
print ("test take pic")
camera_config = camera.create_still_configuration({"size":(4056, 3040)})
camera.configure(camera_config)
print ("test create pic config")
camera.pre_callback = apply_timestamp
print ("test pic config set")
camera.start(show_preview=False)
print ("test cam start")
# camera needs some waiting time after initial configuration
# web tells around 2sec is needed - I take 5sec as the RPi is doing some other CPU consuming stuff during booting phase
time.sleep(5)
print ("test take the pic")
timestamp = dt.now()
timestamp = timestamp.strftime("%Y-%m-%d-%H-%M-%S")
file_name = "pic_test_" + timestamp + ".jpg"
camera.capture_file(file_name)
camera.stop()
print ("test pic taken")
`
Beta Was this translation helpful? Give feedback.
All reactions