I have the model which has class LICENSE PLATE , using yolo i am detecting the object by number plates bounding box , now i need to trigger the camera to awake only when object is detected and once object not detected afterwards my hardware(camera) should go back to sleep or shutdown in some time . in my client app (camera app reolink ) they have motion detection for car as well as for humans i have connected to the camera using rtsp_url . is there any way to link our model to client app so for cars to trigger the script . or is there any other idea direct from cv2? . below code will see camera_on varible but it doesn't work well for me.
if __name__ == '__main__':
rtsp_url = 'YOUR_RTSP_URL'
camera_threaded = Threaded(rtsp_url)
camera_on = False
sleep_time = 5 # Sleep time in 5 seconds
start_time = time.time()
try:
while True:
frame = camera_threaded.get_Fame()
if not camera_on:
try:
if frame is None:
print('Unable to read video')
continue
results = predictions(frame, net)
if len(results) > 0:
# Object detected, turn on the camera or streaming
camera_on = True
start_time = time.time() # Reset the start time
except Exception as e:
print('Error Found : ', str(e))
continue
if camera_on:
try:
if frame is None:
print('Unable to read the video')
continue
results = predictions(frame, net)
cv2.namedWindow('YOLO', cv2.WINDOW_KEEPRATIO)
cv2.imshow('YOLO', brightened_frame)
if len(results) == 0:
# No objects detected, check if sleep time has elapsed
elapsed_time = time.time() - start_time
if elapsed_time >= sleep_time:
camera_on = False # Turn off the camera or streaming
time.sleep(10)
except Exception as e:
print('Error Found here : ', str(e))
continue
key = cv2.waitKey(2)
if key == 27:
cv2.destroyWindow('YOLO')
print('KeyBoard Interuption Occured : Stopping the Program')
break
except KeyboardInterrupt:
print('KeyBoard Interuption Occured: Stopping the Program')
cv2.destroyAllWindows()```