Double Take

repository·master·Indexed 23 days ago

https://github.com/jakowenko/double-take

A unified UI and API for processing and training images for facial recognition. Double Take acts as a management layer that abstracts detection engines such as CompreFace, Amazon Rekognition, Deepstack, and Facebox, integrating them with NVRs like Frigate and automation platforms like Home Assistant. It provides a REST API, MQTT publishing for match results, and a web interface for managing training images and configuration.

Tokens
7.3K
Snippets
12
Records
40
Agent score
80%

What's inside double-take

  1. What is Double Take?

    master
    Double Take is a unified UI and API designed to abstract the complexities of various facial recognition detection services. It allows you to process and train images for facial recognition by combining multiple detectors into a single workflow. It can process images from NVRs (like Frigate), publish results via MQTT, and provide a REST API for integration with other applications.
  2. Store secrets in Home Assistant

    master

    If you are using a Home Assistant Add-on, you can use the Home Assistant secrets.yaml file to store sensitive information like MQTT passwords or API keys using the !secret tag.

    Example usage in config.yml:

    mqtt:
      password: !secret mqtt_password
    
    detectors:
      compreface:
        key: !secret compreface_key

    Corresponding entry in secrets.yaml:

    mqtt_password: <password>
    compreface_key: <api-key>
    mqtt:
      host: localhost
      username: mqtt
      password: !secret mqtt_password
    
    detectors:
      compreface:
        url: localhost:8000
        key: !secret compreface_key
  3. Install Double Take via Docker Compose

    master

    You can deploy Double Take using Docker Compose. The following configuration sets up the service with a persistent volume for storage and exposes the UI/API on port 3000.

    version: '3.7'
    
    volumes:
      double-take:
    
    services:
      double-take:
        container_name: double-take
        image: jakowenko/double-take
        restart: unless-stopped
        volumes:
          - double-take:/.storage
        ports:
          - 3000:3000
  4. Run Double Take locally for development

    master

    To develop on Double Take, you can run the services using Docker containers.

    Available Services:

    • UI: localhost:8080
    • API: localhost:3000
    • MQTT: localhost:1883

    Commands:

    • Start development containers: ./.develop/docker up
    • Remove development containers: ./.develop/docker down
    • Build local image: ./.develop/build
    # start development containers
    ./.develop/docker up
    
    # remove development containers
    ./.develop/docker down
  5. Configure Double Take via config.yml

    master

    Double Take configuration is stored in /.storage/config/config.yml. You can edit these settings directly in the file or via the web UI at http://localhost:3000/config.

    Note: You only need to specify values that differ from the default settings.

  6. Configure camera masks and overrides

    master

    Use the cameras block to define settings for specific cameras. You can apply masks to ignore certain areas or override global detection settings for that specific camera.

    Masks:

    • coordinates: A list of x,y coordinates defining the polygon.
    • visible: If true, shows the mask on the final saved image (useful for debugging).
    • size: The camera stream size used for resizing masks (e.g., 1920x1080).
    cameras:
      front-door:
        # masks:
        #   coordinates:
        #     - 1920,0,1920,328,1638,305,1646,0
        #   visible: false
        #   size: 1920x1080
        # detect:
        #   match:
        #     save: true
        #     base64: false
        #     confidence: 60
        #     min_area: 10000
        #   unknown:
        #     save: true
        #     base64: false
        #     confidence: 40
        #     min_area: 0
        # snapshot:
        #   topic:
        #   url:
  7. Configure detectors (CompreFace, Rekognition, Deepstack, Facebox)

    master

    The detectors block allows you to configure various facial recognition engines. Each detector has specific requirements.

    CompreFace

    • url: CompreFace URL.
    • key: Recognition API key.
    • timeout: Request timeout in seconds.
    • det_prob_threshold: Minimum confidence (0.0 to 1.0) that a recognized face is actually a face.
    • opencv_face_required: Whether to require OpenCV to find a face first.
    • face_plugins: Comma-separated slugs (e.g., mask,gender,age).
    • cameras: List of cameras to process with this detector.

    AWS Rekognition

    • aws_access_key_id: AWS access key.
    • aws_secret_access_key: AWS secret key.
    • aws_region: AWS region.
    • collection_id: Rekognition collection ID.
    • opencv_face_required: Whether to require OpenCV to find a face first.
    • cameras: List of cameras to process.

    Deepstack / Facebox

    • url: Detector URL.
    • key: API key.
    • timeout: Request timeout in seconds.
    • opencv_face_required: Whether to require OpenCV to find a face first.
    • cameras: List of cameras to process.
    detectors:
      compreface:
        url: ""
        key: ""
        timeout: 15
        det_prob_threshold: 0.8
        opencv_face_required: false
        # face_plugins: mask,gender,age
        # cameras:
        #   - front-door
      rekognition:
        aws_access_key_id: !secret aws_access_key_id
        aws_secret_access_key: !secret aws_secret_access_key
        aws_region: ""
        collection_id: double-take
        opencv_face_required: true
        # cameras:
        #   - front-door
      deepstack:
        url: ""
        key: ""
        timeout: 15
        opencv_face_required: false
        # cameras:
        #   - front-door
      facebox:
        url: ""
        key: ""
        timeout: 15
        opencv_face_required: false
        # cameras:
        #   - front-door
  8. Configure MQTT settings

    master

    Use the mqtt block to enable subscribing to and publishing to MQTT topics. This is used for Frigate event subscriptions, Home Assistant discovery, and publishing matches.

    Key configuration options include:

    • host, username, password, client_id
    • tls: For secure connections using cert, key, and ca files.
    • topics:
      • frigate: Topic for Frigate message subscription (default: frigate/events).
      • homeassistant: Topic for Home Assistant discovery (default: homeassistant).
      • matches: Topic where matches are published by name (default: double-take/matches).
      • cameras: Topic where matches are published by camera name (default: double-take/cameras).
  9. Configure MQTT publishing

    master

    Double Take publishes results to specific MQTT topics. You must configure the mqtt.host to enable this.

    Key topics include:

    • double-take/matches/<name>: Publishes match details for a specific subject.
    • double-take/cameras/<camera>: Publishes camera-specific event data.
    • double-take/cameras/<camera>/person: Publishes the number of persons detected (resets to 0 after 30 seconds).
    • double-take/errors: Publishes API errors.
    mqtt:
      host: localhost
  10. Configure Frigate integration

    master

    The frigate block manages how Double Take interacts with Frigate for facial recognition.

    Key options:

    • url: The Frigate URL.
    • update_sub_labels: If true, sends matches back to Frigate as sub-labels (requires Frigate 0.11.0+).
    • stop_on_match: If true, stops processing once a match is found.
    • min_area: Minimum area to ignore small detections.
    • labels: List of object labels allowed for recognition (e.g., person).
    • attempts:
      • latest: Number of times to request latest.jpg.
      • snapshot: Number of times to request snapshot.jpg.
      • mqtt: Boolean to process images from frigate/+/person/snapshot topics.
      • delay: Delay in seconds between detection loops.
    • image.height: Height of the Frigate image passed for recognition.
    • cameras: List of specific cameras to process.
    • zones: List of specific zones to process.
    • events: Per-camera overrides for attempts and image settings.
    frigate:
      url: ""
      update_sub_labels: false
      stop_on_match: true
      min_area: 0
      labels:
        - person
      attempts:
        latest: 10
        snapshot: 10
        mqtt: true
        delay: 0
      image:
        height: 500
      cameras:
        # - front-door
      zones:
        # - camera: garage
        #   zone: driveway
      events:
        # front-door:
        #   attempts:
        #     latest: 5
        #     snapshot: 5
        #     mqtt: false
        #     delay: 1
        #   image:
        #     height: 1000
        #     latest: http://camera-url.com/image.jpg
        #     snapshot: http://camera-url.com/image.jpg
  11. Configure Gotify notifications

    master

    The notify.gotify block allows you to send notifications via Gotify.

    • url: Gotify server URL.
    • token: Gotify application token.
    • priority: Notification priority (e.g., 5).
    • cameras: List of specific cameras to notify from.
    • zones: List of specific zones to notify from (e.g., camera: garage, zone: driveway).
    notify:
      gotify:
        url: ""
        token: ""
        priority: 5
        # cameras:
        #   - front-door
        # zones:
        #   - camera: garage
        #     zone: driveway