def __init__(
        self,
        ip_address,
        port,
        api_key,
        timeout,
        detect_only,
        save_file_folder,
        save_timestamped_file,
        camera_entity,
        name=None,
    ):
        """Init with the API key and model id."""
        super().__init__()
        self._dsface = ds.DeepstackFace(ip_address, port, api_key, timeout)
        self._detect_only = detect_only

        self._last_detection = None
        self._save_file_folder = save_file_folder
        self._save_timestamped_file = save_timestamped_file

        self._camera = camera_entity
        if name:
            self._name = name
        else:
            camera_name = split_entity_id(camera_entity)[1]
            self._name = "{} {}".format(CLASSIFIER, camera_name)
        self._faces = []
        self._matched = {}
        self.total_faces = None
def test_DeepstackFace():
    """Test a good response from server."""
    with requests_mock.Mocker() as mock_req:
        mock_req.post(
            FACE_DETECTION_URL,
            status_code=ds.HTTP_OK,
            json=MOCK_FACE_DETECTION_RESPONSE,
        )

        dsface = ds.DeepstackFace(MOCK_IP_ADDRESS, MOCK_PORT)
        predictions = dsface.detect(MOCK_BYTES)
        assert predictions == MOCK_FACE_DETECTION_RESPONSE["predictions"]
 def __init__(self,
              ip_address,
              port,
              api_key,
              timeout,
              detect_only,
              camera_entity,
              name=None):
     """Init with the API key and model id."""
     super().__init__()
     self._dsface = ds.DeepstackFace(ip_address, port, api_key, timeout)
     self._detect_only = detect_only
     self._camera = camera_entity
     if name:
         self._name = name
     else:
         camera_name = split_entity_id(camera_entity)[1]
         self._name = "{} {}".format(CLASSIFIER, camera_name)
     self._matched = {}
Example #4
0
if deepstack_mode == FACE:
    st.title("Deepstack Face recognition")

    img_file_buffer = st.file_uploader("Upload an image",
                                       type=["png", "jpg", "jpeg"])
    ## Process image
    if img_file_buffer is not None:
        pil_image = Image.open(img_file_buffer)

    else:
        pil_image = Image.open(FACE_TEST_IMAGE)

    dsface = ds.DeepstackFace(
        ip=DEEPSTACK_IP,
        port=DEEPSTACK_PORT,
        api_key=DEEPSTACK_API_KEY,
        timeout=DEEPSTACK_TIMEOUT,
        min_confidence=MIN_CONFIDENCE_THRESHOLD,
    )
    predictions = process_image_face(pil_image, dsface)
    faces = utils.get_faces(predictions, pil_image.width, pil_image.height)
    recognised_faces = [
        face for face in faces if face["confidence"] > CONFIDENCE_THRESHOLD
    ]

    # Draw object boxes
    draw = ImageDraw.Draw(pil_image)
    for face in faces:
        confidence = face["confidence"]
        name = face["name"]
        box_label = f"{name}"