Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viseron v2 #306

Merged
merged 225 commits into from Oct 21, 2022
Merged

Viseron v2 #306

merged 225 commits into from Oct 21, 2022

Conversation

roflcoopter
Copy link
Owner

@roflcoopter roflcoopter commented Dec 4, 2021

This is a huge rewrite of Viseron.
It focuses on decoupling all parts of Viseron, making it more modularized. This allows for easier integration of new functionality.

The config.yaml file will change completely so there is some work that has to be done by each user to port over to the new version.
The general config format is a component which implements one or more domains.
Each camera has a unique camera identifier which flows through the entire configuration.

The nvr component then ties all these different domains together and provides the full functionality.

The big benefit of this new format is that you can mix and match components more freely.
For instance, you could use different object detectors for different cameras, you are not tied into just one.

Config Example
ffmpeg: # <-- component
  camera: # <-- domain
    camera_one: # <-- camera identifier
       name: Camera 1
       host: 192.168.10.10
       username: test
       password: test
    camera_two: # <-- camera identifier
       name: Camera 2
       host: 192.168.10.11
       username: test
       password: test
       ....

darknet: # <-- component
  object_detector: # <-- domain
    model: /my_custom_model/model.weights
    cameras:
      camera_one: # <-- camera identifier
        fps: 5

deepstack:  # <-- component
  host: deepstack # <-- component config option
  port: 5000 # <-- component config option
  object_detector: # <-- domain
    cameras:
      camera_two:  # <-- camera identifier
        fps: 1
        labels:
          - label: person
            confidence: 0.75
            trigger_recorder: false
  face_recognition: # <-- domain
    cameras:
      camera_one:
      camera_two:
    labels:
      - person

background_subtractor: # <-- component
  motion_detector: # <-- domain
    cameras:
      camera_one: # <-- camera identifier
        fps: 1
        mask:
          - coordinates:
              - x: 400
                y: 200
              - x: 1000
                y: 200
              - x: 1000
                y: 750
              - x: 400
                y: 750

nvr: # <-- component
  camera_one: # <-- camera identifier
  camera_two: # <-- camera identifier
Here is a generic config snippet with publicly available cameras that can be used to try it out
ffmpeg:
  camera:
    viseron_camera:
      name: Camera 1
      host: 195.196.36.242
      path: /mjpg/video.mjpg
      port: 80
      stream_format: mjpeg
      fps: 6
      recorder:
        idle_timeout: 1
        codec: h264
    viseron_camera2:
      name: Camera 2
      host: storatorg.halmstad.se
      path: /mjpg/video.mjpg
      stream_format: mjpeg
      port: 443
      fps: 2
      protocol: https
      recorder:
        idle_timeout: 1
        codec: h264
    viseron_camera3:
      name: Camera 3
      host: 195.196.36.242
      path: /mjpg/video.mjpg
      port: 80
      stream_format: mjpeg
      fps: 6
      recorder:
        idle_timeout: 1
        codec: h264

mog2:
  motion_detector:
    cameras:
      viseron_camera:
        fps: 1

background_subtractor:
  motion_detector:
    cameras:
      viseron_camera3:
        fps: 1
        mask:
          - coordinates:
              - x: 400
                y: 200
              - x: 1000
                y: 200
              - x: 1000
                y: 750
              - x: 400
                y: 750

darknet:
  object_detector:
    model_path: /detectors/models/darknet/yolov4-csp-x-swish.weights
    model_config: /detectors/models/darknet/yolov4-csp-x-swish.cfg
    cameras:
      viseron_camera:
        fps: 1
        scan_on_motion_only: false
        labels:
          - label: person
            confidence: 0.2
            trigger_recorder: false
      viseron_camera2:
        fps: 1
        labels:
          - label: person
            confidence: 0.2
            trigger_recorder: false

nvr:
  viseron_camera:
  viseron_camera2:
  viseron_camera3:

webserver:

mqtt:
  broker: ****
  port: 1883
  username: ****
  password: *****
  client_id: viseron
  home_assistant:

logger:
  default_level: debug
  logs:
    viseron.components.data_stream: info
    viseron.components.background_subtractor: info
    viseron.components.mog2: info

End goal is to port all existing functionality and also resolve some of the open issues.

This PR and its description will be updated going forward.

To-do list:

  • EdgeTPU Object detector
  • Darknet Object detector
  • DeepStack Object detector
  • MoG2 Motion detector
  • Background subtractor Motion detector
  • Webserver
  • MQTT
    • Client
    • Home Assistant integration
      • Camera status binary sensors
      • Motion detected binary sensors
      • Object detected binary sensors
      • Face detected binary sensors
      • Sensors
      • Switches
      • Cameras
  • FFmpeg camera
  • Recordings
  • Deepstack Face recognition
  • OpenCV Face recognition
  • Internal Entity registry that components can listen and react to (inspired by Home Assistant)
  • Setup retry functionality of components
  • React based UI
  • Letterbox resizing before object detection
  • Default config generation
  • Remove all old and dead code
  • Update tests
  • Update documentation

Issues to resolve

Bonus features not possible with previous versions of Viseron

  • Multiprocessing
  • Using different object or motion detectors simultaneously

Partial changelog (README has not been updated to reflect this)

Breaking changes

  • ALL kinds of inheritance in the config has been removed.
    This means that you have to explicitly have to configure your object detector and motion detector settings for each nvr.

  • interval has been removed from object_detection and motion_detection
    A new config option fps will be used instead. Please update your configuration.
    This change was made since it was quite confusing, both in the code and for the users because interval was specified in seconds.

  • logging has been removed in all shapes and forms and has been replaced with logger
    Please see the updated documentation

  • cameras config section has been removed. Camera config is now specified under a component.

  • Each object detector has been split up into individual components.
    See the documentation for each detector.

  • Each motion detector has been split up into individual components.
    See the documentation for each detector.

  • recorder can no longer be configured on a global level.
    It now has to be present under each camera configuration.

  • timeout under recorder is now called idle_timeout

  • static_mjpeg_streams are now called mjpeg_streams

  • enable under object_detection is no more. To disable object detection you simply dont configure it for a camera
    Same goes for motion_detector

  • timeout for motion_detector is now called recorder_keepalive

  • max_timeout for motion_detector is now called max_recorder_keepalive

  • Recordings are now stored in the folder structure /recordings/<camera name>/<date>/<timestamp>.mp4

  • filter_args removed for camera and recorder.
    For camera, use video_filters instead.
    For recorder, you can use both video_filters and audio_filters

    Short config example to rotate video 180 degrees:
    ffmpeg:
      camera:
        camera_1:
        ....
          video_filters:   # These filters rotate the images processed by Viseron
            - transpose=2
            - transpose=2
          recorder:
            video_filters:   # These filters rotate the recorded video
              - transpose=2
              - transpose=2

New features

  • New config entry for webserver. See the README for available config options
  • React based Web UI
  • New component gstreamer(!)
    The implementation is quite basic as of now, but this will pave way for a better Jetson Nano integration.
  • New post_processor, image_classification. Right now the edgetpu component has support for it.

Changes

Fixes

  • Fixed detection of usb EdgeTPU, so that permissions are set correctly

@roflcoopter
Copy link
Owner Author

Hi tested.

  • motion and zones working
  • object detection not working (also in mqtt)

My setting as follow;

gstreamer:
  camera:
    camera_1:
      name: anpr_191
      host: 192.168.6.191
      port: 554
      path: '/sub'
      username: 'admin'
      password: '1qaz2wsx'
      fps: 10
      width: 640
      height: 480
      mjpeg_streams:
        camera_1:
          width: 640
          height: 480 
          draw_objects: true
          draw_zones: true
          # draw_motion: true
          # draw_motion_mask: true
          # draw_object_mask: true

darknet:
  object_detector:
    cameras:
      camera_1:  # Attach detector to the configured camera_1 above
        fps: 10
        scan_on_motion_only: false  # Scan for objects even when there is no motion
        zones:
          - name: zone1
            coordinates:
              - x: 631
                y: 252
              - x: 456
                y: 474
              - x: 144
                y: 476
              - x: 454
                y: 247
            labels:
              - label: person
                confidence: 0.1
                trigger_recorder: false
              - label: car
                confidence: 0.1
                trigger_recorder: false
              - label: truck
                confidence: 0.1
                trigger_recorder: false
              - label: motorbike
                confidence: 0.1
                trigger_recorder: false
              - label: bus
                confidence: 0.1
                trigger_recorder: false

background_subtractor: # <-- component
  motion_detector: # <-- domain
    cameras:
      camera_1: # <-- camera identifier

and this is my log when startup

Creating viseron ... done
Attaching to viseron
viseron    | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
viseron    | [s6-init] ensuring user provided files have correct perms...exited 0.
viseron    | [fix-attrs.d] applying ownership & permissions fixes...
viseron    | [fix-attrs.d] done.
viseron    | [cont-init.d] executing container initialization scripts...
viseron    | [cont-init.d] 10-adduser: executing... 
viseron    | /var/run/s6/etc/cont-init.d/10-adduser: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/10-adduser: line 16: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/10-adduser: line 17: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/10-adduser: line 18: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/10-adduser: line 19: log_info: command not found
viseron    | [cont-init.d] 10-adduser: exited 127.
viseron    | [cont-init.d] 20-gid-video-device: executing... 
viseron    | [cont-init.d] 20-gid-video-device: exited 0.
viseron    | [cont-init.d] 30-edgetpu-permission: executing... 
viseron    | /var/run/s6/etc/cont-init.d/30-edgetpu-permission: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/30-edgetpu-permission: line 5: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/30-edgetpu-permission: line 10: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/30-edgetpu-permission: line 12: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/30-edgetpu-permission: line 51: log_info: command not found
viseron    | [cont-init.d] 30-edgetpu-permission: exited 127.
viseron    | [cont-init.d] 40-set-env-vars: executing... 
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 6: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 12: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 28: log_warning: command not found
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 36: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/40-set-env-vars: line 42: log_info: command not found
viseron    | [cont-init.d] 40-set-env-vars: exited 127.
viseron    | [cont-init.d] 50-check-if-rpi: executing... 
viseron    | /var/run/s6/etc/cont-init.d/50-check-if-rpi: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/50-check-if-rpi: line 5: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/50-check-if-rpi: line 23: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/50-check-if-rpi: line 25: log_info: command not found
viseron    | [cont-init.d] 50-check-if-rpi: exited 127.
viseron    | [cont-init.d] 55-check-if-jetson: executing... 
viseron    | /var/run/s6/etc/cont-init.d/55-check-if-jetson: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/55-check-if-jetson: line 5: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/55-check-if-jetson: line 18: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/55-check-if-jetson: line 20: log_info: command not found
viseron    | [cont-init.d] 55-check-if-jetson: exited 127.
viseron    | [cont-init.d] 60-ffmpeg-path: executing... 
viseron    | /var/run/s6/etc/cont-init.d/60-ffmpeg-path: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/60-ffmpeg-path: line 5: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/60-ffmpeg-path: line 8: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/60-ffmpeg-path: line 9: log_info: command not found
viseron    | [cont-init.d] 60-ffmpeg-path: exited 127.
viseron    | [cont-init.d] 70-gstreamer-path: executing... 
viseron    | /var/run/s6/etc/cont-init.d/70-gstreamer-path: line 3: /helpers/logger.sh: No such file or directory
viseron    | /var/run/s6/etc/cont-init.d/70-gstreamer-path: line 5: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/70-gstreamer-path: line 8: log_info: command not found
viseron    | /var/run/s6/etc/cont-init.d/70-gstreamer-path: line 9: log_info: command not found
viseron    | [cont-init.d] 70-gstreamer-path: exited 127.
viseron    | [cont-init.d] done.
viseron    | [services.d] starting services
viseron    | [services.d] done.

Does it work better if you remove the zones config?

@shmrymbd
Copy link

i had pull latest. it is working now. can you share latest working jetson image.

@roflcoopter roflcoopter marked this pull request as ready for review October 21, 2022 13:31
@roflcoopter roflcoopter merged commit 28def1e into dev Oct 21, 2022
@roflcoopter
Copy link
Owner Author

Merging this, will do the last finishing touches in separate PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment