0

I am developing an object detection application using SSD model and I have defined the bounding box and the prob_threshold, when I run the code I realise that the model double count person in frame. Please see below my code

## Setting Pro_threshold for person detection filtering
try:
    prob_threshold = float(os.environ['PROB_THRESHOLD'])
except:
    prob_threshold = 0.4

    
def draw_boxes(frame, result, width, height):
    """
    :Draws bounding box when person is detected on video frame 
    :and the probability is more than the specified threshold
    """
    present_count = 0
    for obj in result[0][0]:
        conf = obj[2]
        if conf >= prob_threshold:
            xmin = int(obj[3] * width)
            ymin = int(obj[4] * height)
            xmax = int(obj[5] * width)
            ymax = int(obj[6] * height)
            cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (0, 255, 0), 3)
            present_count += 1
    return frame, present_count
Machavity
  • 30,841
  • 27
  • 92
  • 100
Godspower
  • 87
  • 2
  • 6

1 Answers1

0
In order to ensure that the number of people in the video frame was not double counted I first initialise the variables and used if statement to calculate the duration spent by each person in the video frame. 

## Initialise variables##
    present_request_id = 0
    present_count = 0
    start_time = 0
    last_count = 0
    total_count = 0

## Calculating the duration a person spent on video#
            if present_count < last_count and int(time.time() - start_time) >=1:
                duration = int(time.time() - start_time)
                if duration > 0:
                    # Publish messages to the MQTT server
                    client.publish("person/duration",
                                   json.dumps({"duration": duration + lagtime}))
                else:
                    lagtime += 1
                    log.warning(lagtime)

adding below argument and experimenting between the seconds, in my case I experimented between 1secs and 3sec

int(time.time() - start_time) >=1

see GitHub Repo for explanation.

Godspower
  • 87
  • 2
  • 6