Exemplo n.º 1
0
def remove_duplicates(blobs):
    for id_a, blob_a in list(blobs.items()):
        for id_b, blob_b in list(blobs.items()):
            if blob_a == blob_b:
                break

            if blob_a.area >= blob_b.area and box_contains_point(
                    blob_a.bounding_box, blob_b.centroid):
                del blobs[id_b]
            elif blob_b.area >= blob_a.area and box_contains_point(
                    blob_b.bounding_box, blob_a.centroid):
                del blobs[id_a]
    return blobs
Exemplo n.º 2
0
def add_new_blobs(boxes, blobs, frame, tracker, current_blob_id, counting_line,
                  line_position, mcdf):
    # add new blobs to existing blobs
    matched_blob_ids = []
    for box in boxes:
        box_centroid = get_centroid(box)
        box_area = get_area(box)
        match_found = False
        for _id, blob in blobs.items():
            if blob.counted == False and box_contains_point(
                    box, blob.centroid):
                match_found = True
                if _id not in matched_blob_ids:
                    blob.num_consecutive_detection_failures = 0
                    matched_blob_ids.append(_id)
                temp_blob = create_blob(
                    box, frame,
                    tracker)  # TODO: update blob w/o creating temp blob
                blob.update(temp_blob.bounding_box, temp_blob.tracker)
                break

        if not match_found and not is_passed_counting_line(
                box_centroid, counting_line, line_position):
            _blob = create_blob(box, frame, tracker)
            blobs[current_blob_id] = _blob
            current_blob_id += 1

    blobs = remove_stray_blobs(blobs, matched_blob_ids, mcdf)
    return blobs, current_blob_id
Exemplo n.º 3
0
def add_new_blobs(boxes, blobs, frame, tracker, current_blob_id):
    # add new blobs to existing blobs
    for box in boxes:
        box_centroid = get_centroid(box)
        box_area = get_area(box)
        match_found = False
        for _id, blob in blobs.items():
            if (blob.area >= box_area and box_contains_point(blob.bounding_box, box_centroid)) \
                    or (box_area >= blob.area and box_contains_point(box, blob.centroid)):
                match_found = True
                temp_blob = create_blob(
                    box, frame,
                    tracker)  # TODO: update blob w/o creating temp blob
                blob.update(temp_blob.bounding_box, temp_blob.tracker)
                break

        if not match_found:
            _blob = create_blob(box, frame, tracker)
            blobs[current_blob_id] = _blob
            current_blob_id += 1
    return blobs, current_blob_id
def add_new_blobs(boxes, blobs, frame, tracker, current_blob_id, counting_line,
                  line_position, mcdf, detector):
    path = 'detectors\yolo'
    labelsPath = os.path.join(path, 'coco.names')
    LABELS = open(labelsPath).read().strip().split("\n")
    # add new blobs to existing blobs
    matched_blob_ids = []
    if detector == 'yolo':
        for box in boxes:
            #print(boxes)
            box_centroid = get_centroid(box[0])
            box_area = get_area(box[0])
            match_found = False
            for _id, blob in blobs.items():
                #print(blobs.items())
                if blob[0].counted == False and box_contains_point(
                        box[0], blob[0].centroid):
                    #((blob.area >= box_area and box_contains_point(blob.bounding_box, box_centroid)) \
                    #or (box_area >= blob.area and box_contains_point(box[0], blob.centroid))):
                    match_found = True
                    if _id not in matched_blob_ids:

                        blob[0].num_consecutive_detection_failures = 0

                        matched_blob_ids.append(_id)
                    temp_blob = create_blob(
                        box[0], frame,
                        tracker)  # TODO: update blob w/o creating temp blob
                    blob[0].update(temp_blob.bounding_box, temp_blob.tracker)
                    break

            if not match_found and not is_passed_counting_line(
                    box_centroid, counting_line, line_position):
                _blob = create_blob(box[0], frame, tracker)
                blobs[current_blob_id] = _blob, LABELS[box[1][0]]
                current_blob_id += 1
    else:
        for box in boxes:
            #print(boxes)
            box_centroid = get_centroid(box)
            box_area = get_area(box)
            match_found = False
            for _id, blob in blobs.items():
                #print(blobs.items())
                if blob.counted == False and box_contains_point(
                        box, blob.centroid):
                    #((blob.area >= box_area and box_contains_point(blob.bounding_box, box_centroid)) \
                    #or (box_area >= blob.area and box_contains_point(box[0], blob.centroid))):
                    match_found = True
                    if _id not in matched_blob_ids:

                        blob.num_consecutive_detection_failures = 0

                        matched_blob_ids.append(_id)
                    temp_blob = create_blob(
                        box, frame,
                        tracker)  # TODO: update blob w/o creating temp blob
                    blob.update(temp_blob.bounding_box, temp_blob.tracker)
                    break

            if not match_found and not is_passed_counting_line(
                    box_centroid, counting_line, line_position):
                _blob = create_blob(box, frame, tracker)
                blobs[current_blob_id] = _blob
                current_blob_id += 1

    blobs = remove_stray_blobs(blobs, matched_blob_ids, mcdf)
    return blobs, current_blob_id