tfaehse / DashcamCleaner

Censor identifiable information in videos, in particular dashcam recordings in Germany.
GNU Affero General Public License v3.0
130 stars 27 forks source link

Fully integrate tracking, rewrite UI integration #87

Open tfaehse opened 6 months ago

tfaehse commented 6 months ago
- blurrer is independent from UI, CLI via generic progress handler
- execution in three stages: detection, tracking, blurring
- choose mps backend automatically on supported hardware (ARM macOS machines)
- add norfair box tracker
- perform tracking forwards and backwards in time
thkukuk commented 6 months ago

With the rename of the options, the Dockerfile needs to be adjusted, too.

thkukuk commented 6 months ago

I did build a container with this PR and got the following error (options were -w 1080p_medium_v8 -t 0.1 -q 5.5 -b 29)

Detecting plates and faces...: 100%|████████████▉| 9065/9067 [6:04:47<00:04,  2.41s/frames]
Running forward tracking...: 100%|████████████████| 9064/9064 [00:13<00:00, 673.96frames/s]
Running backward tracking...: 100%|███████████████| 9063/9063 [00:13<00:00, 654.61frames/s]
Writing blurred video...:  10%|█▊                 | 868/9067 [17:02<1:58:42,  1.15frames/s]concurrent.futures.process._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.10/concurrent/futures/process.py", line 246, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/usr/lib/python3.10/concurrent/futures/process.py", line 205, in _process_chunk
    return [fn(*args) for args in chunk]
  File "/usr/lib/python3.10/concurrent/futures/process.py", line 205, in <listcomp>
    return [fn(*args) for args in chunk]
  File "/app/src/blurrer.py", line 296, in blur_helper
    return apply_blur(frame, index, detections_dict, parameters)
  File "/app/src/blurrer.py", line 343, in apply_blur
    cv2.ellipse(blur_area, center, axes, 0, 0, 360, color=mask_color, thickness=-1)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/drawing.cpp:1953: error: (-215:Assertion failed) axes.width >= 0 && axes.height >= 0 && thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT in function 'ellipse'

"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/cli.py", line 271, in <module>
    cli.start_blurring()
  File "/app/cli.py", line 58, in start_blurring
    self.start_blurring_file()
  File "/app/cli.py", line 69, in start_blurring_file
    blurrer.execute_pipeline()
  File "/app/src/blurrer.py", line 144, in execute_pipeline
    self.write_video(tracking_results)
  File "/app/src/blurrer.py", line 36, in decorator
    return fn(self, *args, **kwargs)
  File "/app/src/blurrer.py", line 220, in write_video
    for frame_blurred in blur_executor.map(blur_helper, args):
  File "/usr/lib/python3.10/concurrent/futures/process.py", line 575, in _chain_from_iterable_of_lists
    for element in iterable:
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 621, in result_iterator
    yield _result_or_cancel(fs.pop())
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 319, in _result_or_cancel
    return fut.result(timeout)
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/drawing.cpp:1953: error: (-215:Assertion failed) axes.width >= 0 && axes.height >= 0 && thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT in function 'ellipse'

Writing blurred video...:  10%|█▊                 | 868/9067 [17:12<2:42:32,  1.19s/frames]
tfaehse commented 6 months ago

Thank you for the feedback. I could reproduce the issue, failed tracks could possibly result in negative axes for the ellipse. The new commit should fix this.

thkukuk commented 6 months ago

I tested the new commit with two videos, no crash, seems to work fine, but there is a bug: the plates and faces of the last four pictures are never blurred.

tfaehse commented 6 months ago

Thank you for the feedback! There are a few more bugs to be fixed, and I'm experimenting with a few more improvements (like using botsort integrated with the detector, and running some simple filtering of tracked obstacles that aren't actively detected anymore), so I've converted this to a draft again.