0

我正在使用 SSD 模型开发对象检测应用程序,并且我已经定义了边界框和 prob_threshold,当我运行代码时,我意识到模型在帧中重复计算了人。请看下面我的代码

## 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
4

1 回答 1

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)

添加以下参数并在几秒钟之间进行试验,在我的情况下,我在 1 秒和 3 秒之间进行了试验

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

参见GitHub Repo以获得解释。

于 2020-06-27T08:53:55.737 回答