Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by Pippo ( 6 years ago )
if len(scores) > 0:
        # Draw distance lines
        # Find the index of the highest score
        max_confidence_box_index = np.argmax(scores)

        # Find the box with the highest confidence score
        max_confidence_box = boxes[max_confidence_box_index]

        # Compute the box width
        box_width = max_confidence_box[2] - max_confidence_box[0]

        # Constant which define the real width of the object
        OBJECT_WIDTH = 0.15 # meters

        # Compute the pixel-per-metric ration
        pixel_per_metric_ratio = OBJECT_WIDTH/box_width

        # Compute centroids
        centroids = np.apply_along_axis(func1d=lambda x:compute_centroid(x),axis=1,arr=np.array(boxes)).astype(int)

        # Retrieve the pairs at risk(MASK-NO_MASK or NO_MASK-NO_MASK)
        pairs_to_check = np.array(list(danger_combinations(range(len(labels)), labels)))

        if pairs_to_check.size != 0:
            # Compute the distances
            real_distances = np.apply_along_axis(func1d = lambda x:compute_distance(x, boxes, centroids, pixel_per_metric_ratio),axis=1,arr=pairs_to_check)

            # Filter pairs at risk by social distancing
            mask = real_distances < 1

            # Draw lines between centroids at risk with relative distance
            for i in range(len(pairs_to_check[mask])):
                # Retrieve the danger pair
                danger_pair = pairs_to_check[mask][i]

                # Compute the mid point coordinates
                x_mid = (centroids[danger_pair[0]] + centroids[danger_pair[1]])[0]//2
                y_mid = (centroids[danger_pair[0]] + centroids[danger_pair[1]])[1]//2


                # Draw a red line that joins the individuals at risk
                cv2.line(cvImage, tuple(centroids[danger_pair[0]]), tuple(centroids[danger_pair[1]]), (0, 0, 255), thickness=2, lineType=8)

                # Add the distance in meters
                cv2.putText(cvImage, "{:.1f}m".format(real_distances[mask][i]), (x_mid, y_mid), cv2.FONT_HERSHEY_SIMPLEX, 0.55, (0, 0, 255), 2)

 

Revise this Paste

Your Name: Code Language: