Skip to content

video_filter: add face detection filter

Brandon Li requested to merge PulseBeat_02/vlc:detect into master

Description: This video filter adds face detection into VLC.


Notes:

  • Used C++ because most modern computer vision libraries don't support C
  • Takes advantage of ShiqiYu/libfacedetection for easy face detection without any dependencies.
    • Created a new detection directory containing the library and my plugin source. There's no existing libfacedetection library you can install, and the library is only four files and the easiest way is to just inline them into the project.
    • Library is licensed under BSD, which is compatible with GPL.
  • Enabled OpenMP support (added option to compile with OpenMP if supported)
  • Algorithm gets frames, and downsizes the image and converts it into grayscale at the same time. If user specifies in arguments to try detection every N times, the previous detection faces are stored and drawn during the stale frames. This is so detection can be faster while giving allowing customizability.

Example Usage: ./vlc --video-filter=facedetection --border-color=#FF0000 --border-thickness=5 --confidence-threshold=75 --detection-frequency=2 --downscale-width=320 --downscale-height=240

  • --video-filter=facedetection: Sets the video filter to be facedetection.
  • --border-color=#FF0000: Sets the rectangle border color (must be RGB hexadecimal color) to red.
  • --border-thickness=5: Sets the rectangle border thickness to be 5 pixels wide.
  • --confidence-threshold=75: Sets the minimum threshold to 75 for any possible detected faces to be drawn.
  • --detection-frequency=2: Sets to try and detect faces every 2nd frame.
  • --downscale-width=320: Sets the downscaled width when downscaling to be 320.
  • --downscale-height=240: Sets the downscaled height when downscaling to be 240.

Lower downscale values sacrifice accuracy for performance, while higher values which persist the resolution will have more accurate results and can detect more faces "farther away" in the image.


Note: The existing face detection plugin isn't an actual plugin (opencv_example_plugin) and hasn't been maintained for 13 years (a lot of the OpenCV headers have since changed). I tried using OpenCV but I ran into a lot of problems because using DNN will result in hard-coding processing logic for specific models, which isn't that great for the end-user.

My module code is in facedetection.cpp.

LTcK0Cn

Edited by Brandon Li

Merge request reports

Loading