noahmr/yolov5-tensorrt

How to get bounding box coordinates and set maximum detection?

beatmonster opened this issue · 4 comments

Hi, i'm currently building a project for detecting ball with real time object detection on jetson platform. The code i'm currently using is the process_live.py and it works perfectly fine but i need the bounding box coordinates and set the maximum detection to only detect 1 ball, can you help me with that? Thanks

Hi @beatmonster, that's awesome! Is this by any chance a RoboCup project ? :))

In the process_live.py example, the place to get the bounding box coordinates would be here:

for d in detections:
    yolov5tensorrt.visualizeDetection(d, image, magenta, 1.0)

All of the detected objects are placed within the 'detections' list. These are of the type 'Detection', which exposes a couple of variables and methods. The one to use here is 'boundingBox', which is gives a tuple (x, y, width, height) containing the coordinates you're looking for. As for limiting it to only 1 detection, you'd probably want to go through the list of detections and pick the object with the highest confidence (which can be accessed through 'score').

If you use the Python 'help' functionality, you can get some more info on all of the Python classes, although at the moment the Python documentation is not quite as good as the C++ documentation.

Feel free to ask if you have any more questions

No, its actually my assignment XD.
Ok, i tried to use the 'boundingBox' but it returns the value of (0,0,0,0). As you can see below is my code:
image
Am i doing it wrong?

Currently you're creating a new Detection object every time, and retrieving the bounding box of that (which is initialized at 0,0,0,0). What you want is to use the Detections produced by the model, which is 'd' in the for-loop. In terms of code, it would look like this:

for d in detections:
    yolov5tensorrt.visualizeDetection(d, image, magenta, 1.0)
    print(d.boundingBox())

Good luck with your assignment, and feel free to reach out if you have more questions

It works now, thank you very much 😄