Jetson inference: Detectnet from RTSP stream

Hello. We trying to use RTSP stream for detection. Very strange situation, that is impossible to understand. Please explain us if possible. Here is the code, that does not work:

import jetson.inference
import jetson.utils
import sys


net = jetson.inference.detectNet("ssd-mobilenet-v2", sys.argv,threshold=0.5)
camera = jetson.utils.videoSource("rtsp://192.168.137.20:8888",argv=sys.argv)
display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

while True:#display.IsStreaming():
 img = camera.Capture()
 detections = net.Detect(img, overlay="box,labels,conf")
 
 display.Render(img)
 display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

and here is the code that works:

import jetson.inference
import jetson.utils
import sys

display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file
net = jetson.inference.detectNet("ssd-mobilenet-v2", sys.argv,threshold=0.5)
camera = jetson.utils.videoSource("rtsp://192.168.137.20:8888",argv=sys.argv)


while True:#display.IsStreaming():
 img = camera.Capture()
 detections = net.Detect(img, overlay="box,labels,conf")
 
 display.Render(img)
 display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

The last message I get before interrupting the code is:

nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1259 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1261 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1263 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1265 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1267 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
nvbuf_utils: dmabuf_fd 1269 mapped entry NOT found
nvbuf_utils: NvReleaseFd Failed... Exiting...
^CTraceback (most recent call last):
  File "hello_test.py", line 14, in <module>
    detections = net.Detect(img, overlay="box,labels,conf")
KeyboardInterrupt

As far as I understand, it doesnt run beyond this line.

The difference is that in working code, the declaration order is different, and camera with rtsp definition comes last. But why the order of declaration is so important, I dont understand.

Hi @ilgar, for some reason when using RTSP, it needs to be created last. I’m not sure why either, as the only difference in the RTSP pipeline is the rtspsrc element (and the networking it uses underneath). The rest of the GStreamer pipeline is the same in that case.

Regardless, I had previously changed the code to detectnet.py to reflect this: https://github.com/dusty-nv/jetson-inference/blob/0ee711633c95e961660fff25fd8aed770a7ff2b6/python/examples/detectnet.py#L51

Thank you for reply. I would like to keep this question unanswered to get possible replies in the future.