theAIGuysCode / yolov4-deepsort

Object tracking implemented with YOLOv4, DeepSort, and TensorFlow.
GNU General Public License v3.0
1.31k stars 745 forks source link

bbox's information and crop object #134

Open farshokat opened 2 years ago

farshokat commented 2 years ago

Hi everyone, I cloned this source. It is very interesting and helpful to many people. I used this source for my project. But, I wanted to crop this object after detection based bbox's information. As I know, the bbox has consisted of x_max, x_min, y_max, y_min. But, I don't know using this information's bbox to crop objects and I using OpenCV. Can you help me with this problem? I don't have a formula. Many thanks to you, and I hoped to help me?

22Raj commented 2 years ago

To crop the detected objects, one thing you can do is add this line in object_tracker.py: cropped_frame = frame[int(bbox[1]):int(bbox[3]),int(bbox[0]):int(bbox[2])]

Somewhere after: for track in tracker.tracks: if not track.is_confirmed() or track.time_since_update > 1: continue bbox = track.to_tlbr() class_name = track.get_class()

And if you want to then save the cropped object as an image:

cv2.imwrite("cropped_"+str(track.track_id)+".png",cropped_frame)