Using the motion project & pygame.camera libraries with a USB webcam on a RPI 4:
I have a python file that works on its own to take a photo then post it to an api.
I want this file to be run when motion is detected on my livestream using on_event_start
.
The livestream works and the file begins as it is supposed to, but when the time comes to take a photo it stops working. I have tried taking a photo on_event_start
and using several other libraries(OpenCV, etc.) to take the photo, but none of them allowed the photo to be taken and the rest of the python file to run.
I have tested on a desktop as well to see if it was just the Pi giving me issues, but it is not. This leads me to believe the issue is that the motion library does not want to allow the camera to be accessed by other libraries (I'm using pygame.camera here) while it is using it for a livestream.
This is the chunk of my python program using the pygame module, where it stops working:
def Photo():
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(1280,720))
cam.start()
time.sleep(1.5)
img = cam.get_image()
global image_name
image_name = 'image_' + date_time + '.jpg'
pygame.image.save(img, image_name)
Photo()
Any suggestions how I could get the pygame module working on top of motion would be appreciated, thanks!