jetson-inference icon indicating copy to clipboard operation
jetson-inference copied to clipboard

How to count the total number of objects

Open shi093 opened this issue 3 years ago • 6 comments

Hi, Dustin, Thank you so much for offering the Hello AI World tutorials. After following the tutorial "Locating Objects with DetectNet", I am wondering how I could count the total number of objects in each image (or video frame). Could you please direct me to the resources that I could use to build on this jetson-inference library and do more customizable counting? Thanks a lot.

shi093 avatar Feb 05 '22 00:02 shi093

Hi @shi093, there is documentation on the detections structures that gets returned by detectNet.Detect() on this page:

https://rawgit.com/dusty-nv/jetson-inference/dev/docs/html/python/jetson.inference.html#detectNet

Detection = <type 'jetson.inference.detectNet.Detection'>
Object Detection Result
 
----------------------------------------------------------------------
Data descriptors defined here:
 
Area
    Area of bounding box
 
Bottom
    Bottom bounding box coordinate
 
Center
    Center (x,y) coordinate of bounding box
 
ClassID
    Class index of the detected [object](https://rawgit.com/dusty-nv/jetson-inference/dev/docs/html/python/__builtin__.html#object)
 
Confidence
    Confidence value of the detected [object](https://rawgit.com/dusty-nv/jetson-inference/dev/docs/html/python/__builtin__.html#object)
 
Height
    Height of bounding box
 
Instance
    Instance index of the detected [object](https://rawgit.com/dusty-nv/jetson-inference/dev/docs/html/python/__builtin__.html#object)
 
Left
    Left bounding box coordinate
 
Right
    Right bounding box coordinate
 
Top
    Top bounding box coordinate
 
Width
     Width of bounding box

You can use this information to build customized statistics and counting of the objects. Or if you simply want to know the total number of detected objects by the DNN, just do len(detections)

dusty-nv avatar Feb 07 '22 16:02 dusty-nv

Dusty, thank you so much for answering my question, really appreciated. Now I am wondering how I could move onto object tracking, i.e., give each detected object a unique ID and track it from frame to frame. I saw some tutorials on object tracking using openCV, but I would like to build the object tracking program on top of the object detection model I re-trained using jetson-inference library. Could you please point me to the right direction for doing this? Thanks again.

shi093 avatar Mar 07 '22 01:03 shi093

Hi @shi093, I don't have tracking functionality in jetson.inference, however DeepStream does and there are ways to use the trained ssd-mobilenet with DeepStream: https://elinux.org/index.php?title=Jetson/L4T/TRT_Customized_Example#Custom_Parser_for_SSD-MobileNet_Trained_by_Jetson-inference

You can also convert the image to numpy array and use the openCV functions for tracking: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-image.md#converting-to-numpy-arrays

https://github.com/dusty-nv/jetson-utils/blob/7de695d94271ba1ae77a4358f427c0887b09084f/python/examples/cuda-to-cv.py

dusty-nv avatar Mar 07 '22 16:03 dusty-nv

@dusty-nv - I have a question regarding the mobilenet ssd v2 parser for deepstream, it says that there should be a .uff file, but we don't have .uff file right? [I am having a custom model trained]

rajeshroy402 avatar Apr 05 '22 17:04 rajeshroy402

The 90-class ssd-mobilenet-v2 that comes with jetson-inference is from TensorFlow (UFF)

However, the custom-trained ssd-mobilenet-v1 models that are trained with PyTorch are ONNX

dusty-nv avatar Apr 05 '22 17:04 dusty-nv

@dusty-nv - I have this issue on forum: https://forums.developer.nvidia.com/t/need-help-in-using-jetson-inference-ssd-v2-with-deepstream/210331

Can you check this or tag someone who can check this?

rajeshroy402 avatar Apr 05 '22 19:04 rajeshroy402