Hey,
I am playing around hailo example, just want to achieve following:
- List item
When people detected, start video recording.
When no people detected, stop video recording.
The detection example can easily do the detection part here.
I tried to add recording function in user_data
def recording(self, has_people):
if has_people :
if not self.is_recording:
self.is_recording = True
tz = datetime.timezone.utc
ft = "%Y-%m-%dT%H:%M:%S"
t = datetime.datetime.now(tz=tz).strftime(ft)
file_name = f'People Detection - {t}.mp4'
self.picam2 = Picamera2()
self.picam2.start()
video_output = FfmpegOutput(file_name)
encoder = H264Encoder(10000000)
print("Starting video recording.")
self.picam2.start_recording(encoder,output=video_output)
else:
if self.is_recording:
print(" Stop video recording")
self.is_recording = False
self.picam2.stop_recording()
self.picam2.stop()
And I got following error
I tried to use the frame from frame object in line 80 with following
def recording(self, has_people, frame):
if has_people :
if not self.is_recording:
print(" Starting record")
self.is_recording = True
if self.video_out_stream:
self.video_out_stream.release()
self.video_out_stream = None
tz = datetime.timezone.utc
ft = "%Y-%m-%dT%H:%M:%S"
t = datetime.datetime.now(tz=tz).strftime(ft)
file_name = f'People Detection - {t}'
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fps = 30
frame_size = (640, 480)
# Create a VideoWriter object
self.video_out_stream = cv2.VideoWriter(file_name+'.mp4', fourcc, fps, frame_size)
print(" Recording ...")
import pdb; pdb.set_trace()
self.video_out_stream.write(frame) # Write the frame to the video
else:
if self.is_recording:
print(" Stop record")
self.is_recording = False
if self.video_out_stream:
self.video_out_stream.release()
self.video_out_stream = None
The mp4 file always empty.
Could you have any suggestion how I can record video if detection_count is greater than zero?