Esempio n. 1
0
def add_new_blobs(boxes, classes, confidences, blobs, frame, tracker,
                  counting_line, line_position, mcdf):
    # add new blobs to existing blobs
    matched_blob_ids = []
    for _idx in range(len(boxes)):
        _type = classes[_idx] if classes != None else None
        _confidence = confidences[_idx] if confidences != None else None

        box_centroid = get_centroid(boxes[_idx])
        box_area = get_area(boxes[_idx])
        match_found = False
        for _id, blob in blobs.items():
            if blob.counted == False and get_iou(boxes[_idx],
                                                 blob.bounding_box) > 0.5:
                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(
                    boxes[_idx], _type, _confidence, frame,
                    tracker)  # TODO: update blob w/o creating temp blob
                blob.update(temp_blob.bounding_box, _type, _confidence,
                            temp_blob.tracker)
                break

        if not match_found and not is_passed_counting_line(
                box_centroid, counting_line, line_position):
            _blob = create_blob(boxes[_idx], _type, _confidence, frame,
                                tracker)
            blob_id = generate_vehicle_id()
            blobs[blob_id] = _blob

    blobs = remove_stray_blobs(blobs, matched_blob_ids, mcdf)
    return blobs
Esempio n. 2
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 get_iou(blob_a.bounding_box, blob_b.bounding_box) > 0.5 and id_a in blobs:
                del blobs[id_a]
    return blobs
Esempio n. 3
0
def remove_duplicates(blobs):
    for id_a, blob_a in list(blobs.items()):
        a=blob_a.bounding_box
        if (a[2]>1/4*640 or a[3]>1/4*480  ) and id_a in blobs:
            del blobs[id_a]
            break
        for id_b, blob_b in list(blobs.items()):

            if blob_a == blob_b:
                break
            b=blob_b.bounding_box
            if  (b[2]>1/4*640 or b[3]>1/4*480  ) and id_b in blobs:
                del blobs[id_b]
                break
            p=get_inside(blob_a.bounding_box, blob_b.bounding_box)
            if p==1 and id_b in blobs:
                del blobs[id_b]
            if p==2 and id_a in blobs:
                del blobs[id_a]

            if get_iou(blob_a.bounding_box, blob_b.bounding_box) > 0.5 and id_a in blobs:
                del blobs[id_a]

    return blobs
Esempio n. 4
0
def add_new_blobs(boxes, classes, confidences, blobs, frame, tracker, counting_line, line_position, mcdf):
    # add new blobs or update existing ones
    matched_blob_ids = []
    for i in range(len(boxes)):
        _type = classes[i] if classes != None else None
        #print (confidences)
        if confidences != []:
            _confidence = confidences[i]
        else:
            _confidence=None

        box_centroid = get_centroid(boxes[i])
        box_area = get_area(boxes[i])
        match_found = False
        for _id, blob in blobs.items():
            #print (_id,blob)
            if blob.counted == False and get_iou(boxes[i], blob.bounding_box) > 0.5:
                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(boxes[i], _type, _confidence, frame, tracker) # TODO: update blob w/o creating temp blob
                blob.update(temp_blob.bounding_box, _type, _confidence, temp_blob.tracker)
                #blob.trajectory

                # Create a sequence of points to make a contour
                #contour=cv2.contourArea([(100,100),(200,200),(500,500)])
                #cv2.pointPolygonTest([(100,100),(200,200),(500,500)], box_centroid, false)
                #area_of_left_left = np.array([[1, 1], [10, 50], [50, 50]], dtype=np.int32)
                # area_of_left_straight=np.array([[1, 1], [10, 50], [50, 50]], dtype=np.int32)
                # area_of_left_right=np.array([[1, 1], [10, 50], [50, 50]], dtype=np.int32)
                # area_of_left=np.array([[1, 1], [10, 50], [50, 50]], dtype=np.int32)

                #left_left = object_in_polygon(frame, area_of_left_left,box_centroid)

                #print(box_centroid)
                #print(left_left)

                log_info('Blob updated.', {
                    'event': 'BLOB_UPSERT',
                    'vehicle_id': _id,
                    'bounding_box': blob.bounding_box,
                    'type': blob.type,
                    'type_confidence': blob.type_confidence,
                    'center': box_centroid,
                    #'direction': direction
                    #'trajectory':trajectory.append
                    #'image': get_base64_image(get_box_image(frame, blob.bounding_box))
                })
                f = './ProcessRecords/Blobupdated58.txt'
                with open(f, "a") as file:
                    file.write(
                        'BLOB_UPSERT' + '-' + 'id' + str(_id) + '-' + 'bounding_box'+str(blob.bounding_box)+'-'+'type' + str(blob.type) + '-' + 'type_confidence' + str(
                            blob.type_confidence) + '-' + 'center' + str(
                            box_centroid) + "\n")

                break

        if not match_found and not is_passed_counting_line(box_centroid, counting_line, line_position):
            _blob = create_blob(boxes[i], _type, _confidence, frame, tracker)
            blob_id = generate_vehicle_id()
            blobs[blob_id] = _blob

            log_info('Blob created.', {
                'event': 'BLOB_UPSERT',
                'vehicle_id': blob_id,
                'bounding_box': _blob.bounding_box,
                'type': _blob.type,
                'type_confidence': _blob.type_confidence,
                'center': box_centroid

                #'image': get_base64_image(get_box_image(frame, _blob.bounding_box))
            })
            f = './ProcessRecords/Blobcreated58.txt'
            with open(f, "a") as file:
                file.write(
                    'BLOB_UPSERT' + '-' + 'id' + str(blob_id) + '-' + 'bounding_box' + str(
                        _blob.bounding_box) + '-' + 'type' + str(_blob.type) + '-' + 'type_confidence' + str(
                        _blob.type_confidence) + '-' + 'center' + str(box_centroid) + "\n")

    blobs = remove_stray_blobs(blobs, matched_blob_ids, mcdf)
    return blobs
Esempio n. 5
0
def add_new_blobs(boxes, classes, confidences, blobs, frame, tracker, counting_line, line_position, mcdf):
    # add new blobs or update existing ones
    matched_blob_ids = []
    print(classes)
    print(boxes)
    for i in range(len(boxes)):
        if classes != []:
            print(classes[i])
            _type = classes[i]
        else:
            _type=None
        print (confidences)
        if confidences != []:
            _confidence = confidences[i]
        else:
            _confidence=None

        box_centroid = get_centroid(boxes[i])
        box_area = get_area(boxes[i])
        match_found = False
        for _id, blob in blobs.items():
            #print (_id,blob)
            if blob.counted == False and get_iou(boxes[i], blob.bounding_box) > 0.5:
                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(boxes[i], _type, _confidence, frame, tracker) # TODO: update blob w/o creating temp blob
                blob.update(temp_blob.bounding_box, _type, _confidence, temp_blob.tracker)
                #blob.trajectory


                # Create a sequence of points to make a contour

                #contour=cv2.contourArea([(100,100),(200,200),(500,500)])
                #cv2.pointPolygonTest([(100,100),(200,200),(500,500)], box_centroid, false)


                log_info('Blob updated.', {
                    'event': 'BLOB_UPSERT',
                    'vehicle_id': _id,
                    'bounding_box': blob.bounding_box,
                    'type': blob.type,
                    'type_confidence': blob.type_confidence,
                    'center': box_centroid,
                    #'direction': direction
                    #'trajectory':trajectory.append
                    #'image': get_base64_image(get_box_image(frame, blob.bounding_box))
                })

                break

        if not match_found and not is_passed_counting_line(box_centroid, counting_line, line_position):
            _blob = create_blob(boxes[i], _type, _confidence, frame, tracker)
            blob_id = generate_vehicle_id()
            blobs[blob_id] = _blob

            log_info('Blob created.', {
                'event': 'BLOB_UPSERT',
                'vehicle_id': blob_id,
                'bounding_box': _blob.bounding_box,
                'type': _blob.type,
                'type_confidence': _blob.type_confidence,
                'centere': box_centroid

                #'image': get_base64_image(get_box_image(frame, _blob.bounding_box))
            })

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