NickM-27 / swatch

Color detection in images to capture presense of known objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Support]: Error when trying to setup Swatch

heisenberg2980 opened this issue · comments

Describe the problem you are having

I am getting the following error after setting up Swatch: requests.exceptions.MissingSchema: Invalid URL 'None': No scheme supplied. Perhaps you meant http://None?

Version

3.1.0

Swatch config file

# REQUIRED: Define a list of objects that are expected to be seen. These can be specific
# to one camera or common between many / all cameras
objects:
  # REQUIRED: Name of the object
  awning:
    # REQUIRED: the list of color variants that this object can be detected as. Useful for
    # different lighting conditions
    color_variants:
      # REQUIRED: the name of the color variant
      default:
        # REQUIRED: the lower R, G, B values that are considered a potential match for the
        # color variant of the object.
        color_lower: 70, 70, 0
        # REQUIRED: the upper R, G, B values that are considered a potential match for the
        # color variant of the object.
        color_upper: 110, 100, 50
        # OPTIONAL: the time range for when this color variant is allowed
        # NOTE: make sure that /etc/localtime is passed to the container so it has valid time
        time_range:
          # OPTIONAL: Color variant is valid if current time is > this 24H time (Default: shown below).
          after: "00:00"
          # OPTIONAL: Color variant is valid if current time is < this 24H time (Default: shown below).
          before: "24:00"
    # OPTIONAL: the min area of the bounding box around groups of matching R, G, B pixels
    # considered a true positive. This is not recommended to be set as a super small amount
    # could be a false positive. (Default: shown below)
    min_area: 1000
    # OPTIONAL: the max area of the bounding box around groups of pixels with R, G, B
    # values within the bounds to be considered a true positive (Default: shown below).
    max_area: 100000
    # OPTIONAL: the min ratio of width/height of bounding box for valid object detection (default: shown below).
    min_ratio: 0
     # OPTIONAL: the max ratio of width/height of bounding box for valid object detection (default: shown below).
    max_ratio: 24000000

# REQUIRED: Define list of cameras that will be used for color detection.
cameras:
  # REQUIRED: Name of the camera
  dahua_3:
    # OPTIONAL: Frequency in seconds to run detection on the camera.
    # a value of 0 disables auto detection (Default: shown below).
    auto_detect: 0
#    # OPTIONAL: Configure the url and retention of snapshots. (Default: Shown Below)
#    snapshot_config:
#        # OPTIONAL: but highly recommended, setting the default url for a snapshot to be
#        # processed by this camera. This is required for auto detection (Default: none).
#        url: "http://ip.ad.dr.ess/jpg"
#        # OPTIONAL: Whether or not to draw bounding boxes for confirmed objects in the snapshots (Default: shown below).
#        bounding_box: true
#        # OPTIONAL: Whether or not to save a clean png of the snapshot along with the annotated jpg (Default: shown below).
#        clean_snapshot: true
#        # OPTIONAL: Whether or not to save the snapshots of confirmed detections (Default: shown below).
#        save_detections: true
#        # OPTIONAL: Whether or not to save the snapshots of missed detections (Default: shown below).
#        save_misses: false
#        # OPTIONAL: Variations of snapshots to keep. Options are all, mask, crop (Default: shown below).
#        mode: "all"
#        # OPTIONAL: Number of days of snapshots to keep (Default: shown below).
#        retain_days: 7
    # REQUIRED: Zones are cropped areas where the object can be expected to be.
    # This makes searching / matches for efficient and more predictable than searching
    # the entire image.
    zones:
      # REQUIRED: Name of the zone.
      top:
        # REQUIRED: Coordinates to crop the zone by.
        # NOTE: The order of the coordinates are: x, y, x+w, y+h starting in the top left corner as 0, 0.
        coordinates: 360, 0, 5600, 80
        # REQUIRED: List of objects that may be in this zone. These correspond to
        # the objects list defined previously and are matched by name.
        objects:
          - awning

Relevant log output

[2023-09-16 10:24:55,500]: ERROR - Exception on /dahua_3/snapshot.jpg [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/opt/swatch/swatch/http.py", line 342, in get_latest_camera_snapshot
    jpg_bytes = current_app.snapshot_processor.get_latest_camera_snapshot(camera_name)
  File "/opt/swatch/swatch/snapshot.py", line 175, in get_latest_camera_snapshot
    img_bytes = requests.get(
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 515, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 443, in prepare_request
    p.prepare(
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 318, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 392, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'None': No scheme supplied. Perhaps you meant http://None?

Any other information that may be helpful

No response

Thanks to @NickM-27 I was able to solve the issue by adding the snapshot URL, which in my case is http://frigate_ip:5000/api/camera_name/latest.jpg as I am using Frigate.

P.S.: it seems snapshot_config is not optional, maybe something to be updated in the comments of the config file example