motioneye-project / motioneye

A web frontend for the motion daemon.
GNU General Public License v3.0
3.93k stars 652 forks source link

Triggering raw picture #2703

Open namork opened 1 year ago

namork commented 1 year ago

Dear all. I'm trying to find out if it is possible to trigger a raw picture when motion is detected in motioneye. This would be very powerful for everybody who uses it as camera trap. I'm using as raspi model 4 with a model 3 noir camera module. Thanks for any help!

namork commented 1 year ago

in /etc/motion/motion.config i found the following line and tried:

Command to be executed when an event starts.

; on_event_start value | libcamera-still -r -o /home/pi/Desktop/camera1/rawtest.jpg

but it won't work as the the libcamera-still command isn't working directly in the terminal either (Unable to set controls: Device or resource busy).

is there a way to stop the video capturing in motion for a couple of seconds?

namork commented 1 year ago

i tried with:

`sudo systemctl stop motion

sleep 1

sudo libcamera-still -r --rotation 180 --tuning-file /usr/share/libcamera/ipa/raspberrypi/imx708noir.json -o /home/pi/Desktop/camera1/$(date +"%Y-%m-%d")/$(date +"%Y-%m-%d%H-%M-%S").jpg --immediate

sleep 10 sudo systemctl start motion sleep 5 `

but this triggers the setup to constantly take raw pictures ;o(

any idea?

namork commented 1 year ago

we now have a working script but don't get it triggered when configured within motioneye. any ideas or workarounds?

from picamera2 import Picamera2, Preview
from libcamera import controls
import subprocess
import time
from datetime import datetime
from datetime import date

subprocess.run(["sudo", "systemctl", "stop", "motioneye"])

time.sleep(1)
print("now")

dt = datetime.now().strftime("%Y-%m-%d_%H-%M-00Z")
date= date.today()
print(str(dt))

picam2 = Picamera2()
camera_config = picam2.create_still_configuration(main={"size": (1920, 1080)}, lores={"size": (640, 480)}, display="lores")
picam2.configure(camera_config)
picam2.start_preview(Preview.NULL)
picam2.start()
picam2.set_controls({"AfMode": controls.AfModeEnum.Auto})

time.sleep(1)
picam2.capture_file("/home/pi/Desktop/cam1/"+str(date)+"/"+str(dt)+".jpg")

time.sleep(1)
subprocess.run(["sudo", "systemctl", "start", "motioneye"])
quit()
namork commented 1 year ago

?