How to keep posenet running if the camera is not detected

Hi,

As the posnet.py start, the IP camera may not be ready, what is a proper way to keep the program from existing?
if(jetson.utils.videoSource(“rtsp…”)):?

I can do “try” in the loop just in case someone unplug the network cable…
try:
img = camera.Capture()
except:
print(“”)

Thx

import jetson.inference
import jetson.utils

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)

#############################################
while not(jetson.utils.videoSource("rtsp........")):
      camera = jetson.utils.videoSource("rtsp........")
#############################################

display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

while display.IsStreaming():
        try:
	      img = camera.Capture()
        except:
	      print("skip frame")
	detections = net.Detect(img)
	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

Hi,

As you said, this can be done by adding some exception handlers.
Add @dusty_nv here for more comments.

Thanks.

Hi @AK51, yes you can use the except handlers, and depending on the behavior of your IP camera you can eventually del camera and re-create it if you need to establish the pipeline again from scratch.

Also, there is an optional timeout parameter to videoSource.Capture() which specifies the timeout in milliseconds. The default is -1, which means never timeout. 0 means return immediately if no frame.

Hi,

I try to make it work, but it seems every trial uses up some resource…
core dumped when the camera begins…


Do you delete (del) the previous videoSource before trying to create a new one? Also, you may need to add some sleep() statements to wait for some time before continually trying to re-connect.

Oh yes. Silly me, after I’ve added the time.sleep(5), it works.
Thx Dusty

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.