fangfufu / Linux-Fake-Background-Webcam

Faking your webcam background under GNU/Linux, now supports background blurring, animated background, colour map effect, hologram effect and on-demand processing.
GNU General Public License v3.0
1.6k stars 161 forks source link

Improve performance #159

Closed gekmihesg closed 3 years ago

gekmihesg commented 3 years ago

In my test setup, this improved my frame rate from 10 FPS to around 30 FPS on 1920x1080 when running ./fake.py -w /dev/video99 -v /dev/video100 --threshold 50 -F60 (where /dev/video99 is a v4l2loopback device, delivering at 60 FPS). Functionality should remain unchanged. It's mostly just replacing some of the code with in-place operations.

fangfufu commented 3 years ago

I will test it tomorrow. What CPU do you have?

gekmihesg commented 3 years ago

I tested this on a Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz

fangfufu commented 3 years ago

Well, this is impressive. Thank you so much!

ronny-rentner commented 2 years ago

Hi, this is pretty cool.

Can you tell what was the main driver for the performance improvement?

How did you debug which call takes how long?

I can see in the manual https://google.github.io/mediapipe/solutions/selfie_segmentation.html they're doing some things like

` # To improve performance, optionally mark the image as not writeable to

pass by reference.

image.flags.writeable = False`

which we don't seem to do in fake.py but I'm not sure if that actually would make a difference.

fangfufu commented 2 years ago

@ronny-rentner, basically rather than performing extra assignments, all the image processing are done in place. In another word, the variables themselves got modified without assignment operations.