Skip to content

Commit

Permalink
[config] Add config option for max threshold #119
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Oct 16, 2023
1 parent 85d1ad1 commit b1ff659
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ There are also several other bugfixes and improvements, such as improved seeking
-detection-parameters)
- [general] Noise reduction kernel can now be disabled by setting `-k`/`--kernel-size` to `0` ([#123](https://github.com/Breakthrough/DVR-Scan/issues/123))
- [general] Include stack traces in logfiles when setting `--verbosity debug`
- [bugfix] Fix CNT mode always treating first few frame as having motion [#119](https://github.com/Breakthrough/DVR-Scan/issues/119)
- [bugfix] Add `max-score` option to config file to fix CNT mode always treating first few frame as motion, default is 255.0 [#119](https://github.com/Breakthrough/DVR-Scan/issues/119)
- [bugfix] Fix timecode format `HH:MM:SS[.nnn]` being rejected for start/end time ([#141](https://github.com/Breakthrough/DVR-Scan/issues/141))
- [bugfix] Fix incorrect RGB mapping for config file (values were treated as BGR instead)
- [other] Config option `timecode` has been renamed to `time-code` to match the command-line option
Expand Down
8 changes: 8 additions & 0 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ The following options control motion detection. A more comprehensive descriptio
```
</span>
* <b><pre>max-threshold</pre></b>
Scores of this amount or higher are ignored. 255.0 is the maximum score, so values greater than 255.0 will disable the filter.
<span class="dvr-scan-default">
```
max-threshold = 255.0
```
</span>
* <b><pre>kernel-size</pre></b>
Size (in pixels) of the noise reduction kernel. Size must be an odd number starting from 3, 0 to disable, or -1 to auto-set based on video resolution.
<span class="dvr-scan-default">
Expand Down
4 changes: 4 additions & 0 deletions dvr-scan.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
# while too low of a threshold can result in false detection events.
#threshold = 0.15

# Scores of this amount or higher are ignored. 255.0 is the maximum score,
# so values greater than 255.0 will disable the filter.
#max-threshold = 255.0

# Size (in pixels) of the noise reduction kernel. Can be odd integer starting
# from 3, 0 to disable, or -1 to auto-set using video resolution.
#kernel-size = -1
Expand Down
1 change: 1 addition & 0 deletions dvr_scan/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def from_config(config_value: str, default: 'RGBValue') -> 'RGBValue':
# Detection Parameters
'bg-subtractor': 'MOG2',
'threshold': 0.15,
'max-threshold': 255.0,
'kernel-size': KernelSizeValue(),
'downscale-factor': 0,
# TODO(v1.7): Remove, replaced with region files.
Expand Down
1 change: 1 addition & 0 deletions dvr_scan/cli/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def run_dvr_scan(settings: ProgramSettings) -> ty.List[ty.Tuple[FrameTimecode, F
scanner.set_detection_params(
detector_type=DetectorType[settings.get('bg-subtractor').upper()],
threshold=settings.get('threshold'),
max_threshold=settings.get('max-threshold'),
kernel_size=settings.get('kernel-size'),
downscale_factor=settings.get('downscale-factor'),
)
Expand Down
9 changes: 4 additions & 5 deletions dvr_scan/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ def __init__(self,
self._threshold = 0.15 # -t/--threshold
self._kernel_size = None # -k/--kernel-size
self._downscale_factor = 1 # -df/--downscale-factor

# TODO(v1.6): Add ability to configure the rejection filter (_max_score_) by adding a
# threshold + amount option (e.g. ignore up to 2 frames in a row that are over score 100).
self._max_score = 255.0
self._max_threshold = 255.0 # max-threshold

# Motion Event Parameters (set_event_params)
self._min_event_len = None # -l/--min-event-length
Expand Down Expand Up @@ -365,11 +362,13 @@ def set_detection_params(
self,
detector_type: DetectorType = DetectorType.MOG2,
threshold: float = 0.15,
max_threshold: float = 255.0,
kernel_size: int = -1,
downscale_factor: int = 1,
):
"""Set detection parameters."""
self._threshold = threshold
self._max_threshold = max_threshold
self._subtractor_type = detector_type
if downscale_factor < 0:
raise ValueError("Downscale factor must be positive.")
Expand Down Expand Up @@ -638,7 +637,7 @@ def scan(self) -> Optional[DetectionResult]:
frame_score = result.score
# TODO(v1.6): Allow disabling the rejection filter or customizing amount of
# consecutive frames it will ignore.
if frame_score >= self._max_score:
if frame_score >= self._max_threshold:
frame_score = 0
above_threshold = frame_score >= self._threshold
event_window.append(frame_score)
Expand Down

0 comments on commit b1ff659

Please sign in to comment.