Git Product home page Git Product logo

obs-face-tracker's Introduction

OBS Face Tracker Plugin

Introduction

This plugin provide a feature to track face of a person by detecting and tracking a face.

This plugin employs dlib on face detection and object tracking. The frame of the source is periodically taken to face detection algorithm. Once a face is found, the face is tracked. Based on the location and the size of the face under tracking, the frame will be cropped.

Usage

For several use cases, total 3 methods are provided.

Face Tracker Source

The face tracker is implemented as a source. You can easily have another source that tracks and zooms into a face.

  1. Click the add button on the source list.
  2. Add Face Tracker.
  3. Scroll to the bottom and set Source property.

See Properties for the description of each property.

Face Tracker Filter

The face tracker is implemented as an effect filter so that any video source can have the face tracker.

  1. Open filters for a source on OBS Studio.
  2. Click the add button on Effect Filters.
  3. Add Face Tracker.

See Properties for the description of each property.

Face Tracker PTZ

Experimental version of PTZ control is provided as an video filter.

  1. Open filters for a source on OBS Studio,
  2. Click the add button on Audio/Video Filters.
  3. Add Face Tracker PTZ.

See Properties for the description of each property.

See Limitations for current limitations of PTZ control feature.

Wiki

Building

This plugin requires dlib to be built. The dlib should be extracted under obs-face-tracker so that it will be linked statically. I modified dlib so that openblasp won't be linked but openblas.

For macOS, install openblas and configure the path.

brew install openblas
export OPENBLAS_HOME=/usr/local/opt/openblas/

For Linux and macOS, expand obs-face-tracker outside obs-studio and build.

d0="$PWD"
git clone https://github.com/obsproject/obs-studio.git
mkdir obs-studio/build && cd obs-studio/build
cmake ..
make
cd "$d0"

git clone https://github.com/norihiro/obs-face-tracker.git
cd obs-face-tracker
git submodule update --init
mkdir build && cd build
cmake .. \
	-DLIBOBS_INCLUDE_DIR=$d0/obs-studio/libobs \
	-DLIBOBS_LIB=$d0/obs-studio/libobs \
	-DOBS_FRONTEND_LIB="$d0/obs-studio/build/UI/obs-frontend-api/libobs-frontend-api.dylib" \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo
make

For Windows, see .github/workflows/main.yml.

Preparing data file

You need to prepare a model file.

HOG model file

Once you have built on Linux or macOS, you will find an executable file face-detector-dlib-hog-datagen.

Assuming your current directory is obs-face-tracker, run it like this.

mkdir data/dlib_hog_model/
./build/face-detector-dlib-hog-datagen > ./data/dlib_hog_model/frontal_face_detector.dat

CNN model file

The CNN model file mmod_human_face_detector.dat.bz2 can be downloaded from dlib-models.

Assuming your current directory is obs-face-tracker, run commands like below.

mkdir data/dlib_cnn_model/
git clone --depth 1 https://github.com/davisking/dlib-models
bunzip2 < dlib-models/mmod_human_face_detector.dat.bz2 > data/dlib_cnn_model/mmod_human_face_detector.dat

5-point face landmark model file

The 5-point face landmark model file shape_predictor_5_face_landmarks.dat.bz2 can be downloaded from dlib-models.

Assuming your current directory is obs-face-tracker, run commands like below.

mkdir data/dlib_face_landmark_model/
git clone --depth 1 https://github.com/davisking/dlib-models
bunzip2 < dlib-models/shape_predictor_5_face_landmarks.dat.bz2 > data/dlib_face_landmark_model/shape_predictor_5_face_landmarks.dat

68-point face landmark model file

Note

The 68-point face landmark model is a non-free license. . Check README for the restriction.

If you want to use the 68-point face landmark model file shape_predictor_68_face_landmarks.dat.bz2, run commands like below.

mkdir data/dlib_face_landmark_model/
git clone --depth 1 https://github.com/davisking/dlib-models
bunzip2 < dlib-models/shape_predictor_68_face_landmarks.dat.bz2 > data/dlib_face_landmark_model/shape_predictor_68_face_landmarks.dat

Installing the model files

Once you have prepared the model files under data directory, run cd build && make install so that the data file will be installed.

Known issues

This plugin is heavily under development. So far these issues are under investigation.

  • Memory usage is gradually increasing when continuously detecting faces.
  • It consumes a lot of CPU resource.
  • The frame sometimes vibrates because the face detection results vibrates.

License

This plugin is licensed under GPLv2.

Sponsor

  • Jimcom USA - a company of Live Streaming and Content Recording Professionals. Development of PTZ camera control is supported by Jimcom. Jimcom is now providing a 20% discount for their broadcast-quality network-connected PTZ cameras and free shipping in the USA. Visit Jimcom USA and enter the coupon code FACETRACK20 when you order.

Acknowledgments

obs-face-tracker's People

Contributors

norihiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obs-face-tracker's Issues

PTZ: Improve format compatibility

default:
if (TEST_FORMAT(frame->format))
blog(LOG_ERROR, "unsupported frame format %d. Check enum video_format in obs-studio/libobs/media-io/video-io.h for the format code.", (int)frame->format);

This code should use video scaler (video_scaler_t) from obs-studio so that any format can be converted.

[BUG] OBS 27.0.1

20:08:43.202: 	video device: FaceTime HD Camera (Built-in)
20:08:43.202: 	video path: \\?\usb#vid_05ac&pid_8514&mi_00#7&26c477d1&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global
20:08:43.202: 	resolution: 640x480
20:08:43.202: 	flip: 0
20:08:43.202: 	fps: 30.00 (interval: 333333)
20:08:43.202: 	format: NV12
20:08:45.013: effect_setval_inline: invalid param
20:08:47.013: effect_setval_inline: invalid param
20:08:49.013: effect_setval_inline: invalid param
20:08:49.296: [obs-face-tracker] ftf_preset_load: loading preset 
20:08:49.297: [obs-face-tracker] ftf_preset_load: preset  does not exist
20:08:50.540: [obs-face-tracker] ftf_preset_save: deleting preset 
20:08:51.013: effect_setval_inline: invalid param
20:08:53.013: effect_setval_inline: invalid param
20:08:55.013: effect_setval_inline: invalid param
20:08:57.013: effect_setval_inline: invalid param
20:08:59.013: effect_setval_inline: invalid param
20:09:01.013: effect_setval_inline: invalid param
20:09:03.013: effect_setval_inline: invalid param
20:09:05.013: effect_setval_inline: invalid param
20:09:07.013: effect_setval_inline: invalid param
20:09:09.013: effect_setval_inline: invalid param
20:09:11.013: effect_setval_inline: invalid param
20:09:13.013: effect_setval_inline: invalid param
20:09:15.013: effect_setval_inline: invalid param
20:09:17.013: effect_setval_inline: invalid param
20:09:19.013: effect_setval_inline: invalid param
20:09:21.013: effect_setval_inline: invalid param
20:09:23.013: effect_setval_inline: invalid param
20:09:25.013: effect_setval_inline: invalid param
20:09:27.013: effect_setval_inline: invalid param
20:09:29.013: effect_setval_inline: invalid param
20:09:31.013: effect_setval_inline: invalid param
20:09:33.013: effect_setval_inline: invalid param
20:09:35.013: effect_setval_inline: invalid param
20:09:37.013: effect_setval_inline: invalid param
20:09:39.013: effect_setval_inline: invalid param
20:09:41.013: effect_setval_inline: invalid param
20:09:43.013: effect_setval_inline: invalid param
20:09:45.013: effect_setval_inline: invalid param
20:09:47.013: effect_setval_inline: invalid param
20:09:49.013: effect_setval_inline: invalid param
20:09:51.013: effect_setval_inline: invalid param
21:02:21.779: Last log entry repeated for 1575 more lines

Installation Images Download

Hello,

sorry if I ask a totally stupid question, but for the hell I cannot find the download files for obs-face-tracker. I wanted to install it on macOS according to the Wiki instructions, but I have no idea where to get the dmg from.

Could you please point out, where the files reside?

Thanks a lot.

ptz: Connect through obs-ptz

Thinking the user experiences, this plugin should send commands to the camera through the other plugin obs-ptz so that a user can install both plugin and use at the same time. Especially VISCA over serial port cannot be controlled from individual program.
glikely/obs-ptz#17

EL8: openblas is missing for link libraries

A library openblas need to be added target_link_libraries.

Error

When face detection starts, I got this error.

obs: symbol lookup error: /usr/local//lib/obs-plugins/obs-face-tracker.so: undefined symbol: dgesvd_

Environment

OS: CentOS8

Solution

Add openblas to target_link_libraries(${CMAKE_PROJECT_NAME} ...).

Other comments

It would be better performance to enable openblas for Windows and MacOS build.
I don't know about Ubuntu behavior. Maybe it's better to add.

Preset for parameters

This is a feature request to have a preset of parameters.

Motivation

  • Some parameters are difficult to adjust
  • There is a need to change parameters to make a dynamic move

Consideration

  • Maybe the preset can change track_x/y/z, scale_max, and PID control parameters at once. Or, should I separate PID?
  • The preset can be added by user as well.
  • Assigning to hotkeys would be useful.

Idea: State machine based control

Having these states and switch between them so that the behavior is closer to real camera operator

  • PID control state; same as current tracking
    • If the move of the subject becomes slower, transit to Slow down state.
  • Slow down state; gradually reduce gain of PID control
    • If the move of the subject becomes stable, transit to Freeze state.
    • If the move of the subject becomes faster, transit back to PID control state.
  • Freeze state; don't move camera at all
    • If the subject goes to out of frame or the moving speed exceeds a threshold, transit back to PID control state.

Improve zoom and tracking from wide shot

When zooming from the most wide shot, it start to zoom toward the center at first, then gradually move to the face.
Expected behavior is zoom toward the face from the beginning.

Face Tracker starts from the initial condition when transit to Program

Conditions

  • Duplicate Sources and Duplicate Scene are both enabled.
  • Face Tracker is added to a Group, which contains a camera or video source.

Since the internal state of Face Tracker is not copied, Face Tracker start from the initial location.
I found this issue when looking into #14 but this is a different issue originally reported.

New Feature: Face landmark detection

  • Add face landmark detection.
  • Put textures on the face optionally. And not render the original texture optionally.
  • If this is accurate and fast, it can replace correlation-tracker and will detect lost face earlier.
    • No, face landmark detection requires the bounding box accurately.

Plug in does not appear in filters list.

May not be supported but I'm running Monterey on a MBP M1. Everything looks good as far as installation goes but the plugin doesn't show up in the filters list for my camera.

FEATURE REQUEST: PTZ VISCA (or other) Control

Hi,

Great plugin detecting the face, it would be nice if rather than a zoomed out and digital zoom to the area of interest that the software would control a PTZ Camera to track and optimize the image resolution.

That is, the PTZ control would move the camera left/right/up/down and zoom in or out to help maximize the persons face.

Certainly it would be nice to extend this to bodies as people might not be facing the camera and if there are multiple bodies to include as many as possible.

Thanks for the work on this!

Apply translation on other layer / Additional smoothing

THX , great plugin! & sorry for abusing issue tracking for feature requests:

I am building a multicam virtual studio in OBS. After some tweaking the tracker works quite well on 4K
live input, yet - as expected - I run into problems as soon as there are multiple faces in the picture, and it uses about 50% CPU.
I wish I could run the tracker on separate layer with just the raw live input - possibly down scaled to save CPU -
then apply translation on the group that contains my complete scene the way the "Move Source" plugin that comes with
move transition works: https://obsproject.com/forum/resources/move-transition.913/
We would need X/Y scale and offset to make this work I on scenes, where live input is not same size as the scene itself.

This might be useful for additional smoothing:
https://cristal.univ-lille.fr/~casiez/1euro/

(hover) wiki for attributes

Hi @norihiro ,

Thanks for the great plugin!
Played around with it for the first time today and it was a lot of fun and we will use it a lot in the future.

What I couldn't find is a basic explanation what each attribute or setting actually does?
A couple are explained in the wiki but not all of them.

The best way would be little hover infos next to the settings, but of course a basic web page would do the trick too.

Thanks again for your work!

Not showing up in filters list.

Hello I have installed this plugin on both of my PCs but it will not show up in the filters list, Is there something I am missing?

Error log shows noting is wrong.

Windows 10

Latest OBS

Suppress logs

I should suppress logs that is shown for each iteration

Separate main algorithm to different process

To avoid OBS Studio from potential crashing, main algorithm should be separated from the OBS Studio.
Drawback will be slow data transfer if using pipe, complicated implementation if using shared memory.

Support For Portrait Webcam

If my webcam is on its side, with the capture rotated 90°, the Face Tracker no longer works. Is it possible to make the tracker function if the webcam is rotated?

Compilation failed on Win64

Thanks for the author's update, I followed your updated compilation guide, generated the sln project under win10 64 bit, compile it, and encountered some errors. Please check it out!

error1
error2
error3

Fedora 34 coudn't open libflexiblas.so.3

Getting the following error with selfcompiled obs-face-tracker & obs-studio installed via flatpak

13:50:39.080: os_dlopen(/home/user/.var/app/com.obsproject.Studio/config/obs-studio/plugins/obs-face-tracker/bin/64bit/obs-face-tracker.so->/home/user/.var/app/com.obsproject.Studio/config/obs-studio/plugins/obs-face-tracker/bin/64bit/obs-face-tracker.so): libflexiblas.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
13:50:39.080: 
13:50:39.080: Module '/home/user/.var/app/com.obsproject.Studio/config/obs-studio/plugins/obs-face-tracker/bin/64bit/obs-face-tracker.so' not loaded

connot load '(null)'

The face tracker is not working, I just compiled using the same instructions as the azure pipline for linux
(though I am using manjaro, not ubuntu)
The regular face tracking filter does not work, I tried the PTZ version for fun to just see what it does, and when enabling the detection it detects me nicely

I tried both latest main and v0.2.2

I am using a NDI capture source for my webcam

logs for the regular tracker

17:06:23.122: [obs-face-tracker] face_detector_base: starting the thread.
17:06:23.122: [obs-face-tracker] Cannot load '(null)' (face-tracker.effect)

logs for the ptz tracker

17:06:44.669: [obs-face-tracker] face_detector_base: starting the thread.
17:06:44.696: [obs-face-tracker] received frame format=5

I hope this is enough, If you need me to collect more information, please let me know

New Feature: Move smoothly when clicking reset button

As the main idea, after pressing the RESET button, the KPI value is scaled back to its original size.
The idea is that if the face is not tracked, or if there is a mistake, it can be elegantly returned to the original size, instead of directly switching to the original size.

I think it might be possible to make a checkbox option so that "directly RESET" and "elegant RESET" can coexist.

My English is not very good, so if there is anything I can't understand, please talk to me.

Thanks to the developer for creating such a great plug-in!

Earlier detection of lost face

Even if the face is lost from the frame, the tracker is still remaining for a long time.
It should be cleaned up in a reasonable time.

#55 could be one of the solutions.

Idea/Request: Image or Mask on track

I'd like to see the ability to use the tracker to apply an image or mask to the video source. The tracking is quite effective with appropriate lighting, and there is a lack of effective, straightforward plugins for OBS to use face coverings that track tightly.

Doc: Write a tips for low resolution sources

If the resolution is too small to detect a face, the face tracker does not work.
I'd like to add an FAQ entry to describe how to apply face tracker filter for the low resolution sources.

  1. Expand the source on a scene
  2. Apply the filter to the scene

Screenshot would be helpful to understand how to operate on OBS Studio.

Compilation instructions

Can you provide a smoother description of the win 10 compilation process? It seems a bit tricky. Thank you.

Bugs out when user is away

It just zooms in on where it last tracked my face and doesn't track when I come back. "Reset Tracking" doesn't work, the only solution is to delete filter and add it again, which resets the preferences set.

New Feature: Put weights based on previous detection results

The idea comes from a discussion on the forum.
https://obsproject.com/forum/threads/face-tracker.144419/post-543304

  1. Some sort if setting that when several faces are detected, more weight is given to the last face detected, and/or more weight is given to the face closest to the center of the frame, and/or if another face is detected, it won't be selected if it's more than a settable distance from the current face. These will keep the tracking from bouncing from one face to the next.

Tracking face on 16:9 video and converting to 9:16 without zooming

Hello there!

I am planning to use this plugin to convert the 16:9 live video to 9:16 for streaming to Instagram. (I am also streaming at 16:9 on another computer to other platforms.) So it would be great to add a 9:16 aspect ratio to the existing list of the final video dimensions. Now the closest aspect ratio to portrait is 4:3. It would be also great to add a possibility not to zoom at all (now the minium zoom is 0,10). With these 2 little improvements, I guess this plugin could serve very well on purposes when wanting to track a face in landscape video to convert to portrait video.

Thank you very much for developing this plugin!
Jeremias

Filter does to appear with deb install on Mint 20.1

OBS 27.01 installed on Mint 20.01 (Mate)

deb install puts .so in: /usr/lib/x86_64-linux-gnu/obs-plugins/obs-face-tracker.so
Needed to add link to the rest of the plugins for it to appear in OBS.

sudo ln -s /usr/lib/x86_64-linux-gnu/obs-plugins/obs-face-tracker.so /usr/lib/obs-plugins/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.