예제 #1
0
def _get_in_out_for_camera(camera_id: str):
    in_out_file_path = InOutMetric.get_in_out_file_path(
        camera_id, get_config())
    in_out_boundaries = InOutMetric.read_in_out_boundaries(in_out_file_path)
    if not in_out_boundaries:
        return []
    return [{
        "name": in_out["name"],
        "ax": in_out['in_out_boundary'][0][0],
        "ay": in_out['in_out_boundary'][0][1],
        "bx": in_out['in_out_boundary'][1][0],
        "by": in_out['in_out_boundary'][1][1],
    } for in_out in in_out_boundaries["in_out_boundaries"]]
예제 #2
0
async def get_in_out_boundaries(camera_id: str):
    """
        Get the In/Out Boundaries for a camera.
        Each In/Out boundary in the list is represented by a name and:
        Two coordinates `[x,y]` are given in 2-tuples `[A,B]`. These points form a **line**.
        - If someone crosses the **line** while having **A** to their right, they are going in the `in` direction (entering).
        - Crossing the **line** while having **A** to their left means they are going in the `out` direction (leaving).
    """
    validate_camera_existence(camera_id)
    in_out_file_path = InOutMetric.get_in_out_file_path(camera_id, settings.config)
    in_out_boundaries = InOutMetric.read_in_out_boundaries(in_out_file_path)
    if in_out_boundaries is None:
        error_detail = f"There is no defined In/Out Boundary for {camera_id}"
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=error_detail)
    return InOutBoundaries(**dict(in_out_boundaries))
예제 #3
0
async def remove_in_out_boundaries(camera_id: str, reboot_processor: Optional[bool] = True):
    """
        Delete the defined In/Out boundaries for a camera.
    """
    validate_camera_existence(camera_id)
    in_out_file_path = InOutMetric.get_in_out_file_path(camera_id, settings.config)
    if not validate_file_exists_and_is_not_empty(in_out_file_path):
        detail = f"There is no defined In/Out Boundary for {camera_id}"
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
    os.remove(in_out_file_path)
    success = restart_processor() if reboot_processor else True
    return handle_response(None, success, status.HTTP_204_NO_CONTENT)
예제 #4
0
def map_camera(camera_name, config, options=[]):
    camera_dict = map_section_from_config(camera_name, config)
    camera = config.get(camera_name)
    camera_id = camera.get("Id")
    image_string = None
    if "withImage" in options:
        image_string = get_camera_default_image_string(camera_id)
    camera_dict["image"] = image_string
    calibration_file_path = get_camera_calibration_path(settings.config, camera_id)
    camera_dict["has_been_calibrated"] = validate_file_exists_and_is_not_empty(calibration_file_path)
    roi_file_path = ObjectsFilteringPostProcessor.get_roi_file_path(camera_id, settings.config)
    camera_dict["has_defined_roi"] = validate_file_exists_and_is_not_empty(roi_file_path)
    in_out_file_path = InOutMetric.get_in_out_file_path(camera_id, settings.config)
    camera_dict["has_in_out_border"] = validate_file_exists_and_is_not_empty(in_out_file_path)
    return camera_dict
예제 #5
0
async def add_or_replace_in_out_boundaries(camera_id: str, body: InOutBoundaries, reboot_processor: Optional[bool] = True):
    """
        Create or replace the In/Out boundaries for a camera.
        Each In/Out boundary in the list is represented by a name and:
        Two coordinates `[x,y]` are given in 2-tuples `[A,B]`. These points form a **line**.
        - If someone crosses the **line** while having **A** to their right, they are going in the `in` direction (entering).
        - Crossing the **line** while having **A** to their left means they are going in the `out` direction (leaving).
    """
    validate_camera_existence(camera_id)
    in_out_file_path = InOutMetric.get_in_out_file_path(camera_id, settings.config)
    dir_path = Path(in_out_file_path).parents[0]
    Path(dir_path).mkdir(parents=True, exist_ok=True)
    in_out_boundaries = body.dict()
    with open(in_out_file_path, "w") as outfile:
        json.dump(in_out_boundaries, outfile)
    restart_processor() if reboot_processor else True
    return body