Detectnet - object in frames

Hello,
As my adventure with imageAi fail with not enough fps, I started with jetson.inference.
How can I reach result as on this picture: obraz

Code i pretty simple:

import jetson.inference
import jetson.utils

net = jetson.inference.detectNet(threshold=0.5)
camera = jetson.utils.videoSource(“csi://0”)
display = jetson.utils.videoOutput(“display://0”)

while display.IsStreaming():
img = camera.Capture()
detections = net.Detect(img)
display.Render(img)
display.SetStatus(“Object Detection | Network {:.0f} FPS”.format(net.GetNetworkFPS()))

1 Like

Hi @nerk, that image is not from jetson-inference, so you would need to re-train the detection network on a dataset of construction equipment from aerial perspective.

Regarding the performance, the default detection model in jetson-inference (ssd-mobilenet-v2) was trained on the 90-class MS COCO dataset, so the model has a lot of classes. And the detection performance scales with the number of classes. So if you were to train your own model with fewer classes, it would speed it up.

Alternatively, you can look to DeepStream and training the models with Transfer Learning Toolkit for more optimized performance.

I explained incorrect, my mistake.
I would add bounding boxes, and avoid color mask on picture:
If you can fallow me to right path I will be grateful.

I tried do something like this:

import jetson.inference
import jetson.utils
import cv2
import numpy as np

net = jetson.inference.detectNet(argv=[“–output-bbox=boxes”,“–alpha=0”, “batch=5”],threshold=0.5)
camera = jetson.utils.videoSource(“csi://0”)
display = jetson.utils.videoOutput(“display://0”)

while display.IsStreaming():

img = camera.Capture()
image = img
detections = net.Detect(img)
cv_img = jetson.utils.cudaToNumpy(img)
for detection in detections:
x = detection.Left
y = detection.Right
w = detection.Bottom
h = detection.Top

         cv2.rectangle(cv_img, (x, h), (y, w), (0, 0, 255), 2)

bgr_img = jetson.utils.cudaFromNumpy(cv_img, isBGR=True)
print(“x,y,w,h:”,x,y,w,h)
display.Render(bgr_img)
display.SetStatus(“Object Detection | Network {:.0f} FPS”.format(net.GetNetworkFPS()))

OK gotcha - call net.Detect() with the overlay='none' argument, then detectNet will skip overlaying the bounding boxes, allowing you to do it in OpenCV.

Also, cudaToNumpy() maps the memory into numpy (instead of copying it), so changes that are made it in OpenCV should show up in the original memory. I believe that should allow you to skip the cudaFromNumpy() part after.