AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.75k stars 7.96k forks source link

How to compute the distance between two boundary boxes in YOLOv4 using Linux? #8200

Open janmin123 opened 3 years ago

janmin123 commented 3 years ago

I have followed https://medium.com/geekculture/train-a-custom-yolov4-object-detector-on-linux-49b9114b9dc8 this tutorial to create a custom yolov4 object detector on my linux OS Ubuntu 18.04. I am trying to use the detector in real-time to

1)identify a robotic gripper and a toothpaste box (DONE) 2)identify the actions of the robotic gripper during pick and place of a toothpaste box (e.g I need to identify when the robotic gripper is at home position, pre pick position, picking position) (NOT DONE).

I am trying to execute 2) by obtaining the center coordinates of the gripper and toothpaste box and writing a python or bash shell script to compute the relationship between the two center coordinates, thereby, identifying the actions of the gripper. I call the command "./darknet detector demo data/obj.data cfg/yolov4-custom.cfg backup/yolov4-custom_best.weights -c 0 -ext_output > results.txt" and a tab appears, showing the real-time object detection on my camera feed. At the terminal, the confidence score and coordinates of the boundary boxes of the gripper and toothpaste box are output in real-time. I am also able to access the file results.txt that has saved information aforementioned. However, my question is, how should I go about writing a python or bash shell script to access the box coordinates in the results.txt in order to compute the relationship between the two boxes? And how can I "call" that script in the CLI along with the command to call the YOLOv4 detector "./darknet detector demo data/obj.data cfg/yolov4-custom.cfg backup/yolov4-custom_best.weights -c 0 -ext_output > results.txt"? Thank you so much, any help is appreciated

E.g

The gripper box center - x:0 y:0

The toothpaste box center - x:10 y:-10

Output: Gripper is at home position

The gripper box center - X:10 y:0

The toothpaste box center - x:10 y:-10

Output: Gripper is at pre-pick position (gripper is directly above object)

The gripper box center - X:10 y:-10

The toothpaste box center - x:10 y:-10

Output: Gripper is at pick position (gripper is picking object)

The gripper box center - X:10 y:0

The toothpaste box center - x:10 y:0

Output: Gripper has picked object and is at pre-pick position

lsd1994 commented 3 years ago

You can use darknet as a so lib, then you can get the real time detections.

janmin123 commented 3 years ago

Hi @lsd1994 , thank you so much for your reply and help. Sorry but, I am a newbie to all these. May I know how exactly can I go about doing it?

lsd1994 commented 3 years ago

This is how to compile and use so lib https://github.com/AlexeyAB/darknet#how-to-use-yolo-as-dll-and-so-libraries See the example and check how to get the detection results, then write you own code to compute the distance.