0

So I've been scouring GitHub looking for answers but haven't yet found the solution, so I will be grateful for any help! I am trying to make a DIY trail camera; and I have an IP camera providing me an RTSP feed, I want to capture this feed and take photos based on a PIR motion sensor (HC-SR50); I am running this off a raspberry PI remotely; However the image is stuck on the first frame, and saves the first image from RTSP feed; and then saves and outputs the same image over and over; whilst imshow() shows the live feed fine (this is commented out below asit was interrupting the code)

I figured out that when I do imshow() it was alsostuck- and managed to resolve this by searching this site; (see code)

I am using the TAPO cameras.

the issue seems to be in the While loop where the pir_wait_for_motion begins; thanks in advance for any help!!


from gpiozero import MotionSensor
import cv2
from datetime import datetime
import time
import getpass

**SO THIS PART WORKS OK **

rtsp in

rtsp_url = 'rtsp://user:pass@IP/stream2'
#vlc-in
#output
writepath = "OUTPUTPATH"
pir = MotionSensor(4)
cap = cv2.VideoCapture(rtsp_url)
frameRate = cap.get(5)

Just to show that the RTSP feed was working, all ok so commented out for now as it blocked the rest of the code from running. (Below) So this part isn't so necessary for now.

- while cap.isOpened(): 
- flags, frame = cap.read() 
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
- cv2.startWindowThread() 
- cv2.imshow('RGB OUTPUT', gray) 
- key = cv2.waitKey(1) 
- cv2.destroyAllWindows() 

The below part is where the problem seems to be, however I can't figure out how to keep the frames moving from RTSP feed.


#Image Capture while cap.isOpened(): 
pir.wait_for_motion() 
print("Motion") 
ret, frame = cap.read() 
if (ret != True): 
break
cc1 = datetime.now() 
c2 = cc1.strftime("%Y") 
c3 = cc1.strftime("%M") 
c4 = cc1.strftime("%D") 
c5 = cc1.strftime("%H%M%S") 
hello = "image"+c2+c3+c5 
hellojoin = "".join(hello.split()) 
#photo write 
cv2.imwrite(f'{writepath}/{hellojoin}.png', frame) 
print("image saved!") 
pir.wait_for_no_motion()

cap.release() cv2.destroyAllWindows()

I wanted a PIR motion sensor to capture images from RTSP based on activity infront of sensor; basically acting as a trail camera/camera trap would.

0 Answers0