Beispiel #1
0
    def __init__(self, config, source, live_feed_enabled=True):
        self.config = config
        self.detector = None
        self.device = self.config.get_section_dict('Detector')['Device']

        self.live_feed_enabled = live_feed_enabled
        self.log_time_interval = float(self.config.get_section_dict("Logger")["TimeInterval"])  # Seconds

        self.classifier = None
        self.classifier_img_size = None
        self.face_mask_classifier = None

        self.running_video = False
        self.tracker = CentroidTracker(
            max_disappeared=int(self.config.get_section_dict("PostProcessor")["MaxTrackFrame"]))
        self.camera_id = self.config.get_section_dict(source)['Id']
        self.logger = Logger(self.config, self.camera_id)
        self.image_size = [int(i) for i in self.config.get_section_dict('Detector')['ImageSize'].split(',')]
        self.default_dist_method = self.config.get_section_dict('PostProcessor')["DefaultDistMethod"]

        if self.config.get_section_dict(source)["DistMethod"]:
            self.dist_method = self.config.get_section_dict(source)["DistMethod"]
        else:
            self.dist_method = self.default_dist_method

        self.dist_threshold = self.config.get_section_dict("PostProcessor")["DistThreshold"]
        self.resolution = tuple([int(i) for i in self.config.get_section_dict('App')['Resolution'].split(',')])
        self.birds_eye_resolution = (200, 300)

        if self.dist_method == "CalibratedDistance":
            calibration_file = get_camera_calibration_path(
                self.config, self.config.get_section_dict(source)["Id"])
            try:
                with open(calibration_file, "r") as file:
                    self.h_inv = file.readlines()[0].split(" ")[1:]
                    self.h_inv = np.array(self.h_inv, dtype="float").reshape((3, 3))
            except FileNotFoundError:
                logger.error("The specified 'CalibrationFile' does not exist")
                logger.info(f"Falling back using {self.default_dist_method}")
                self.dist_method = self.default_dist_method

        # config.ini uses minutes as unit
        self.screenshot_period = float(self.config.get_section_dict("App")["ScreenshotPeriod"]) * 60
        self.bucket_screenshots = config.get_section_dict("App")["ScreenshotS3Bucket"]
        self.uploader = S3Uploader(self.config)
        self.screenshot_path = os.path.join(self.config.get_section_dict("App")["ScreenshotsDirectory"], self.camera_id)
        if not os.path.exists(self.screenshot_path):
            os.makedirs(self.screenshot_path)

        if "Classifier" in self.config.get_sections():
            self.face_threshold = float(self.config.get_section_dict("Classifier").get("MinScore", 0.75))
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
async def config_calibrated_distance(camera_id: str, body: ConfigHomographyMatrix, reboot_processor: Optional[bool] = True):
    """
    Calibrates the camera <camera_id> receiving as input the coordinates of a square of size 3ft 3" by 3ft 3" (1m by 1m).
    """
    dir_source = next((source for source in settings.config.get_video_sources() if source["id"] == camera_id), None)
    if not dir_source:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"The camera: {camera_id} does not exist")
    dir_path = get_camera_calibration_path(settings.config, camera_id)
    compute_and_save_inv_homography_matrix(points=body, destination=dir_path)
    sections = settings.config.get_sections()
    config_dict = {}
    for section in sections:
        config_dict[section] = settings.config.get_section_dict(section)
    config_dict[dir_source["section"]]["DistMethod"] = "CalibratedDistance"
    success = update_config(config_dict, reboot_processor)
    return handle_response(None, success, status.HTTP_204_NO_CONTENT)
Beispiel #4
0
 def __init__(self, config, source: str, post_processor: str):
     self.config = config
     self.post_processor = self.config.get_section_dict(post_processor)
     self.dist_threshold = float(self.post_processor["DistThreshold"])
     default_dist_method = self.post_processor["DefaultDistMethod"]
     if self.config.get_section_dict(source).get("DistMethod"):
         self.dist_method = self.config.get_section_dict(source).get("DistMethod")
     else:
         self.dist_method = default_dist_method
     if self.dist_method == self.CALIBRATED_DISTANCE:
         calibration_file = get_camera_calibration_path(
             self.config, self.config.get_section_dict(source)["Id"])
         try:
             with open(calibration_file, "r") as file:
                 self.h_inv = file.readlines()[0].split(" ")[1:]
                 self.h_inv = np.array(self.h_inv, dtype="float").reshape((3, 3))
         except FileNotFoundError:
             logger.error("The specified 'CalibrationFile' does not exist")
             logger.info(f"Falling back using {default_dist_method}")
             self.dist_method = default_dist_method