def update(self, _bounding_box, _tracker=None): self.bounding_box = _bounding_box self.centroid = get_centroid(_bounding_box) self.area = get_area(_bounding_box) self.frames += 1 if _tracker: self.tracker = _tracker
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
def update(self, _bounding_box, _tracker=None): self.bounding_box = _bounding_box self.centroid = get_centroid(_bounding_box) self.area = get_area(_bounding_box) self.classID = get_classID(_bounding_box) if _tracker: self.tracker = _tracker
def update(self, _bounding_box, _type=None, _confidence=None, _tracker=None): self.bounding_box = _bounding_box self.type = _type if _type != None else self.type self.type_confidence = _confidence if _confidence !=None else self.type_confidence self.centroid = get_centroid(_bounding_box) self.area = get_area(_bounding_box) if _tracker: self.tracker = _tracker
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
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