mhnasseri / sort_oh

Simple Online and Real time Tracking with Occlusion Handling
46 stars 11 forks source link

How can I replace the original SORT module? #1

Open software3daerospace opened 3 years ago

software3daerospace commented 3 years ago

Hello @mhnasseri,

Thanks for the good work. I have been facing the ID switches and fragmentation issues from using the original SORT algorithm. I would like to know how I can use your code in place of the original SORT code?

My current application is like this:

        ret, img = cap.read()
        i+= 1

        detected_items = []                                                    # A list containing the information about the detected objects

        # Construct a blob from the given image
        blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), swapRB=True, crop=False)    
        net.setInput(blob)                                                      # Set the blob as input to the network
        layer_outputs = net.forward(output_layers)                              # Perform a single forward pass to get the detections

        class_ids, confidences, b_boxes, history = [], [], [], []                            

        # Loop through each detection
        for output in layer_outputs:
            for detection in output:
                scores = detection[5:]
                class_id = np.argmax(scores)
                confidence = scores[class_id]

                # Create the bounding box with the detection
                center_x, center_y, w, h = (detection[0:4] * np.array([width, height, width, height])).astype('int')
                x = int(center_x -(w / 2))
                y = int(center_y -(h / 2))
                b_boxes.append([x, y, int(w), int(h)])
                confidences.append(float(confidence))
                class_ids.append(int(class_id))
        # Perform non-maxima suppression to filter the bounding boxes
        try:
            indices = cv2.dnn.NMSBoxes(b_boxes, confidences, CONF_THRESH, NMS_THRESH).flatten().tolist()
        except AttributeError:
            pass

        #detected_items = np.asarray(detected_items)
        history = np.asarray(history).astype("int")

        tracks = tracker.update(detected_items)

I instantiate an object of the Sort class in some previous line, so tracker is the name of the object.

What I would want is to be able to use this same code but with the sort_oh module instead. So, for an example output, it would be something like:

from libs import tracker

trk = tracker.Sort_OH()
.
.
.
.
  # generate predictions, push them into the detected_items list
  tracks = trk.update(detected_items)

When I try this example, I get an error saying that I have to provide ground truths as well as the detections. Now, I do not have ground truths, I just have the detections from each image of a video. Is there a possibility of not having to use ground truths?

dsnsabari commented 2 years ago

@software3daerospace did you resolve this issue?

mhnasseri commented 2 years ago

In the tracker_app.py file, there is a 'phase' variable. (Line 42) Changing this variable from 'train' to 'test' cause the algorithm to only generate the results and do not compare them with the ground truth.

dsnsabari commented 2 years ago

@mhnasseri thank you so much