Giter Site home page Giter Site logo

fangfufu / linux-fake-background-webcam Goto Github PK

View Code? Open in Web Editor NEW
1.6K 28.0 160.0 7.67 MB

Faking your webcam background under GNU/Linux, now supports background blurring, animated background, colour map effect, hologram effect and on-demand processing.

License: GNU General Public License v3.0

Dockerfile 1.57% Shell 15.45% Python 82.98%
mediapipe tensorflow-lite opencv-python webcam-background v4l2loopback webcam akvcam

linux-fake-background-webcam's Issues

fakecam error

Hi,
When using DOCKER with default docker-compose yaml file, I get this message:

for linux-fake-background-webcam-master_fakecam_1 Cannot start service fakecam: error gathering device information while adding custom device "/dev/video2": no such file or directory

My computer is a Lenovo machine with 1 camera BUT 2 /dev/video: /dev/video0 (real camera) and
/dev/video1 (metadata camera)

Tx for any help.

Can't pick correct size?

I have an old webcam, so it works best at 640x480. However, it errors out if I specify something that isn't 1280x720 (default) for size, despite the fact I can't find 720 anywhere in the code (I tried changing the default).

Traceback (most recent call last):
  File "./fake.py", line 364, in <module>
    main()
  File "./fake.py", line 360, in main
    loop.run_until_complete(cam.run())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "./fake.py", line 274, in run
    self.put_frame(frame)
  File "./fake.py", line 254, in put_frame
    self.fake_cam.schedule_frame(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
  File "/home/ryan/src/third-party/Linux-Fake-Background-Webcam/venv/lib/python3.7/site-packages/pyfakewebcam/pyfakewebcam.py", line 68, in schedule_frame
    raise Exception('frame height does not match the height of webcam device: {}!={}\n'.format(self._settings.fmt.pix.height, frame.shape[0]))
Exception: frame height does not match the height of webcam device: 720!=480

I'm using v4l2loopback 0.12.5 backported to Debian Buster (running a backports kernel). I have the latest python modules installed in a venv.

It's running slower out of the blue.

I noticed since just this morning that Linux-Fake-Background-Webcam is running a bit slower with some delay. Like I said on reddit, it was running flawlessly. My node and python3 CPU consumption was around 13% combined. Now it's around 35%.

Proof: https://www.youtube.com/watch?v=DkyoLct74tg&feature=youtu.be

I have no idea how to troubleshoot Node JS, though I saw something different running node app.js .

Before: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions: AVX2 FMA

Now: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

I don't remember doing nothing different from before to now.

Allow blurring existing background

It would be great to be able to blur the background instead of completely replacing it. For certain scenarios, like semi-formal conference calls, streaming, video producing, etc, a blurred background works better than a replaced one.

tfjs running out of GPU memory

Upon first installation, running node app.js in the bodypix directory starts up fine. It's not until after starting the fake.py script in the fakecam directory that the crash happens. Error received is:

2020-09-03 11:04:54.209026: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

After a lot of digging, I discovered by running watch -n 0.1 nvidia-smi that once fake.py starts up, the GPU memory immediately climbs to the max (8GB for me) and then the node app crashes with the error. I fixed it by doing the following. Perhaps this could be included in the repository in case it could save others from the same problems.

Inside the bodypix directory:

  1. Install dotenv package npm install dotenv
  2. Create a new file .env
  3. Add TF_FORCE_GPU_ALLOW_GROWTH=true in .env and save it
  4. Add require('dotenv').config(); in app.js on line number 1

cant start docker

I always get the following error:

no source element for URI "/dev/video0"

I tried to use every possible settings in the docker-compose file. If I list my devices I can see the following list:

`# v4l2-ctl --list-devices
Vimicro USB Camera (Altair): Vi (usb-0000:00:14.0-1.7):
/dev/video4
/dev/video5
/dev/media2

Integrated_Webcam_HD: Integrate (usb-0000:00:14.0-6):
/dev/video0
/dev/video1
/dev/video2
/dev/video3
/dev/media0
/dev/media1`

I want to use the Vimicro USB Camera. According to the list above what would be the proper device setting in the compose file?

devices:
# input (webcam)
- /dev/video4:/dev/video4
# output (virtual webcam)
- /dev/video5:/dev/video6

Can you please give me some instructions?

Thanks
Adam

Invalid signature during installation of OpenCV dependencies

The build process returns an error when trying to install the packages listed in the .fakecam/Dockerfile
starting at line 5.

Step 1/9 : FROM python:3
3: Pulling from library/python
Digest: sha256:3df040cc8e804b731a9e98c82e2bc5cf3c979d78288c28df4f54bbdc18dbb521
Status: Downloaded newer image for python:3
---> b55669b4130e
Step 2/9 : RUN pip install --upgrade pip
---> Using cache
---> 422cb4859c68
Step 3/9 : RUN apt-get update &&   apt-get install -y   `# opencv requirements`   libsm6 libxext6 libxrender-dev   `# opencv video opening requirements`   libv4l-dev
---> Running in 9d3af7efff8d
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Err:2 http://security.debian.org/debian-security buster/updates InRelease
At least one invalid signature was encountered.
Err:1 http://deb.debian.org/debian buster InRelease
At least one invalid signature was encountered.
Err:3 http://deb.debian.org/debian buster-updates InRelease
At least one invalid signature was encountered.
Reading package lists...
W: GPG error: http://security.debian.org/debian-security buster/updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://security.debian.org/debian-security buster/updates InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian buster InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian buster InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian buster-updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian buster-updates InRelease' is not signed.
The command '/bin/sh -c apt-get update &&   apt-get install -y   `# opencv requirements`   libsm6 libxext6 libxrender-dev   `# opencv video opening requirements`   libv4l-dev' returned a non-zero code: 100

Any suggestions how to fix this?

cv2.error

self.images["background"] = cv2.resize(background, (self.width, self.height))
fakecam_1 | cv2.error: OpenCV(4.2.0) ../modules/imgproc/src/resize.cpp:4048: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'
fakecam_1 |
linux-fake-background-webcam_fakecam_1 exited with code 1

It seems that the Opencv 4.2 resize function had been changed

UPDATE:
in docker-compose make sure you are tailor the /dev/video lines

GPU Accelerated Version

Is it possible to release a version with GPU acceleration in mind? If not, how do you suggest I modify the code? By the way, I am not using docker to implement this.

Bodypix scaling breaks fake.py (?)

Is it possible that c156ee9 had broken fake.py? I'm not sure if it is related to my docker setup, does it work for you @fangfufu ?

fakecam_1  | Running...
fakecam_1  | Please press CTRL-\ to exit.
fakecam_1  | Please CTRL-C to reload the background image
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 85, in <module>
fakecam_1  |     frame = get_frame(cap, background)
fakecam_1  |   File "fake.py", line 75, in get_frame
fakecam_1  |     frame[:,:,c] = frame[:,:,c]*mask + background[:,:,c]*inv_mask
fakecam_1  | ValueError: operands could not be broadcast together with shapes (720,1280) (360,640) 

docker akvcam not working

I'm using built-in webcam

I got this error

fakecam_1  | Cannot set camera property 3 to 1280, used value: 640.0
fakecam_1  | Cannot set camera property 5 to 30, used value: 10.0
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 397, in <module>
fakecam_1  |     main()
fakecam_1  |   File "fake.py", line 368, in main
fakecam_1  |     cam = FakeCam(
fakecam_1  |   File "fake.py", line 120, in __init__
fakecam_1  |     self.fake_cam = AkvCameraWriter(v4l2loopback_path, self.width, self.height)
fakecam_1  |   File "/src/akvcam.py", line 14, in __init__
fakecam_1  |     self.d = self.open_camera()
fakecam_1  |   File "/src/akvcam.py", line 30, in open_camera
fakecam_1  |     ioctl(d, v4l2.VIDIOC_S_FMT, vid_format)
fakecam_1  | OSError: [Errno 22] Invalid argument
fakecam_1  | Exception ignored in: <function AkvCameraWriter.__del__ at 0x7f1bb007e5e0>
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "/src/akvcam.py", line 48, in __del__
fakecam_1  |     self.queue.put(None)
fakecam_1  | AttributeError: 'AkvCameraWriter' object has no attribute 'queue'

Here's my docker-compose.yml

  version: '3'                                                                                                                                                        
  services:                                                                                                                                                           
      bodypix:                                                                                                                                                        
          image: bodypix                                                                                                                                              
          build:                                                                                                                                                      
              context: ./bodypix                                                                                                                                      
          read_only: true                                                                                                                                             
                                                                                                                                                                      
      fakecam:                                                                                                                                                        
          image: fakecam                                                                                                                                              
          build:                                                                                                                                                      
              context: ./fakecam                                                                                                                                      
          read_only: true                                                                                                                                             
          volumes:                                                                                                                                                    
           - ./fakecam/background.jpg:/src/background.jpg:ro                                                                                                         
           - ./fakecam/foreground.jpg:/src/foreground.jpg:ro                                                                                                         
           - ./fakecam/foreground-mask.png:/src/foreground-mask.png:ro                                                                                               
          devices:                                                                                                                                                    
              # input (webcam)                                                                                                                                        
             - /dev/video0:/dev/video0                                                                                                                               
              # output (virtual webcam)                                                                                                                               
             - /dev/video1:/dev/video2                                                                                                                               
          depends_on:                                                                                                                                                 
              - bodypix                                                                                                                                               
         entrypoint: [ 'python3', '-u', 'fake.py', '-v', '/dev/video2', '-B', 'http://bodypix:9000/', "--no-foreground", '--akvcam']

My device

$ ls -ltrh /dev/video*
crw-rw----+ 1 root video 81, 1 Oct 21 07:25 /dev/video1
crw-rw----+ 1 root video 81, 0 Oct 21 07:25 /dev/video0

And I follow your instruction to install avkcam using DKMS

What am I missing here? 🤔️

HSV color removal

fangfufu, thank you for this collection of tools and for putting in the effort to iterate over the original blogpost.
This has worked for me immediately.

Unfortunately using bodypix gives me 2-3 frames per second on my core m5 cpu, so I prepared another iteration on top of your code on https://github.com/christf/fakebackground. This uses color removal via hsv key.

The effects are similar to the bodypix approach and yield a 11-15 FPS performance on my CPU, yet requires a green cloth for the background.

It could be interesting to work on the wobbling and to improve on the image processing - maybe using bodypix every second or two to re-assess the hsv values from the background and then do the more efficient background calculation for realtime processing of the data.

Anyways - I just wanted to say hi and thank you

Cheers
christf

How to select source video feed

Hi.

Managed to get the code installed and working but I can only use the default laptop camera, not the second USB webcam I usually use on an external monitor.

Is this configured in the v4l2loopback module options ? I know I need to make it use /dev/video1 as the input stream rather than /dev/video0 but it is not clear to me how I do that.

Pete

AMD GPU

Is there a way to get this working with and gpus and maybe even AMD integrated gpus?

Invalid argument error

Hi!

Following all the steps, I get the following error when I run python3 fake.py

Traceback (most recent call last):
  File "fake.py", line 24, in <module>
    fake = pyfakewebcam.FakeWebcam('/dev/video2', width, height)
  File "/home/sasha/.local/lib/python3.6/site-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

But when I run ls /dev | grep -P '^video\d+$', I get:

video0
video1
video2

Thanks!

CPU fallback?

Note that if you don't manage to set up Nvidia Container Toolkit, Tensorflow will fall back to CPU. This is in fact how I run mine - my GPU is too old for the current version of Tensorflow.

But this still requires you to have Nvidia hardware? With my Intel chipset I get "Error response from daemon: could not select device driver "" with capabilities: [[gpu]]" when starting the bodypix container.

AttributeError: 'Namespace' object has no attribute 'fps'

I'm getting this error when running the program. I've tried both manual and via docker compose. I've included the logs and my docker compose file below.

$ docker-compose up
Starting linux-fake-background-webcam_bodypix_1 ... done
Recreating linux-fake-background-webcam_fakecam_1 ... done
Attaching to linux-fake-background-webcam_bodypix_1, linux-fake-background-webcam_fakecam_1
bodypix_1  | 2020-05-27 17:35:14.481877: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
bodypix_1  | 2020-05-27 17:35:14.493556: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2100940000 Hz
bodypix_1  | 2020-05-27 17:35:14.493897: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x6faad80 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
bodypix_1  | 2020-05-27 17:35:14.493920: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 273, in <module>
fakecam_1  |     main()
fakecam_1  |   File "fake.py", line 250, in main
fakecam_1  |     fps=args.fps,
fakecam_1  | AttributeError: 'Namespace' object has no attribute 'fps'
linux-fake-background-webcam_fakecam_1 exited with code 1
^CGracefully stopping... (press Ctrl+C again to force)
Stopping linux-fake-background-webcam_bodypix_1   ... done
version: '3'
services:
    bodypix:
        image: bodypix
        build:
            context: ./bodypix
        read_only: true

    fakecam:
        image: fakecam
        build:
            context: ./fakecam
        read_only: true
        volumes:
          - /home/thomas/Pictures/camera-background/background.jpg:/src/background.jpg:ro
          - /home/thomas/Pictures/camera-background/foreground.jpg:/src/foreground.jpg:ro
          - /home/thomas/Pictures/camera-background/foreground-mask.png:/src/foreground-mask.png:ro
        devices:
            # input (webcam)
            - /dev/video2:/dev/video2
            # output (virtual webcam)
            - /dev/video4:/dev/video4
        depends_on:
            - bodypix
        entrypoint: [ 'python3', '-u', 'fake.py', '-b', 'http://bodypix:9000/']

OSError: [Errno 22] Invalid argument

$ python3 fake.py 
Cannot set camera property 3 to 1280, used value: 0.0
Cannot set camera property 4 to 720, used value: 0.0
Cannot set camera property 5 to 30, used value: 0.0
Traceback (most recent call last):
  File "fake.py", line 397, in <module>
    main()
  File "fake.py", line 368, in main
    cam = FakeCam(
  File "fake.py", line 118, in __init__
    self.fake_cam = pyfakewebcam.FakeWebcam(v4l2loopback_path, self.width, self.height)
  File "/home/hugh/.local/lib/python3.8/site-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

Background Image is read in as video

i am trying to load another background image but I keep getting this error

Traceback (most recent call last):
File "./fake.py", line 397, in
main()
File "./fake.py", line 393, in main
loop.run_until_complete(cam.run())
File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "./fake.py", line 297, in run
frame = await self.mask_frame(session, frame)
File "./fake.py", line 260, in mask_frame
background_frame = next(self.images["background"])
File "./fake.py", line 202, in next_frame
self.bg_video_adv_rate = round(self.bg_video_fps/self.current_fps)
ZeroDivisionError: float division by zero

Error running node

Hi!
I'm getting the following error when running node:

$ node app.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '@tensorflow/tfjs-node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/home/jose/Linux-Fake-Background-Webcam-master/bodypix/app.js:1:12)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Info on system:
[code]

System: Host: mx Kernel: 4.19.0-6-amd64 x86_64 bits: 64 compiler: gcc v: 8.3.0
parameters: BOOT_IMAGE=/boot/vmlinuz-4.19.0-6-amd64
root=UUID=39ae572a-7ca5-480b-add7-387526f94788 ro quiet splash
Desktop: Xfce 4.14.2 tk: Gtk 3.24.5 info: xfce4-panel wm: xfwm4 dm: LightDM 1.26.0
Distro: MX-19.1_x64 patito feo February 15 2020 base: Debian GNU/Linux 10 (buster)
Machine: Type: Laptop System: LENOVO product: VILG1 v: Lenovo G400s serial: Chassis:
type: 10 v: Lenovo G400s serial:
Mobo: LENOVO model: INVALID v: K0E50515STD serial: UEFI: LENOVO
v: 7BCN38WW(V2.04) date: 12/10/2013
Battery: ID-1: BAT1 charge: 15.2 Wh condition: 25.6/37.6 Wh (68%) volts: 14.9/14.4
model: LENOVO PABAS0241231 type: Li-ion serial: status: Unknown
CPU: Topology: Dual Core model: Intel Core i5-3230M bits: 64 type: MT MCP arch: Ivy Bridge
family: 6 model-id: 3A (58) stepping: 9 microcode: 21 L2 cache: 3072 KiB
flags: avx lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 20752
Speed: 3020 MHz min/max: 1200/3200 MHz Core speeds (MHz): 1: 2994 2: 3007 3: 2993
4: 2993
Vulnerabilities: Type: itlb_multihit status: KVM: Split huge pages
Type: l1tf mitigation: PTE Inversion; VMX: conditional cache flushes, SMT vulnerable
Type: mds mitigation: Clear CPU buffers; SMT vulnerable
Type: meltdown mitigation: PTI
Type: spec_store_bypass
mitigation: Speculative Store Bypass disabled via prctl and seccomp
Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer sanitization
Type: spectre_v2 mitigation: Full generic retpoline, IBPB: conditional, IBRS_FW,
STIBP: conditional, RSB filling
Type: tsx_async_abort status: Not affected
Graphics: Device-1: Intel 3rd Gen Core processor Graphics vendor: Lenovo driver: i915 v: kernel
bus ID: 00:02.0 chip ID: 8086:0166
Display: x11 server: X.Org 1.20.4 driver: modesetting unloaded: fbdev,vesa
resolution: 1366x76860Hz, 1280x72060Hz
OpenGL: renderer: Mesa DRI Intel Ivybridge Mobile v: 4.2 Mesa 18.3.6 compat-v: 3.0
direct render: Yes
Audio: Device-1: Intel 7 Series/C216 Family High Definition Audio vendor: Lenovo
driver: snd_hda_intel v: kernel bus ID: 00:1b.0 chip ID: 8086:1e20
Sound Server: ALSA v: k4.19.0-6-amd64
Network: Device-1: Qualcomm Atheros AR8162 Fast Ethernet vendor: Lenovo driver: alx v: kernel
port: 2000 bus ID: 01:00.0 chip ID: 1969:1090
IF: eth0 state: up speed: 100 Mbps duplex: full mac:
Device-2: Qualcomm Atheros AR9485 Wireless Network Adapter vendor: Lenovo
driver: ath9k v: kernel port: 2000 bus ID: 02:00.0 chip ID: 168c:0032
IF: wlan0 state: down mac:
Drives: Local Storage: total: 931.51 GiB used: 230.56 GiB (24.8%)
ID-1: /dev/sda vendor: Seagate model: ST1000LM024 HN-M101MBB size: 931.51 GiB
block size: physical: 4096 B logical: 512 B speed: 6.0 Gb/s rotation: 5400 rpm
serial: rev: 0001 temp: 30 C scheme: GPT
Partition: ID-1: / raw size: 423.55 GiB size: 415.90 GiB (98.19%) used: 79.11 GiB (19.0%)
fs: ext4 dev: /dev/sda10
ID-2: swap-1 size: 3.90 GiB used: 0 KiB (0.0%) fs: swap swappiness: 15 (default 60)
cache pressure: 100 (default) dev: /dev/sda9
Sensors: System Temperatures: cpu: 63.0 C mobo: N/A
Fan Speeds (RPM): N/A
Repos: No active apt repos in: /etc/apt/sources.list
No active apt repos in: /etc/apt/sources.list.d/d-apt.list
Active apt repos in: /etc/apt/sources.list.d/debian-stable-updates.list
1: deb http://deb.debian.org/debian/ buster-updates main contrib non-free
Active apt repos in: /etc/apt/sources.list.d/debian.list
1: deb http://deb.debian.org/debian/ buster main contrib non-free
2: deb http://deb.debian.org/debian-security/ buster/updates main contrib non-free
3: deb http://deb.debian.org/debian/ buster-backports main contrib non-free
Active apt repos in: /etc/apt/sources.list.d/dropbox.list
1: deb [arch=i386,amd64] http://linux.dropbox.com/debian/ buster main
Active apt repos in: /etc/apt/sources.list.d/google-chrome.list
1: deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
Active apt repos in: /etc/apt/sources.list.d/megasync.list
1: deb https://mega.nz/linux/MEGAsync/Debian_10.0/ ./
Active apt repos in: /etc/apt/sources.list.d/mx.list
1: deb https://mxlinux.c3sl.ufpr.br/mx-workspace/mx/repo/ buster main non-free
Active apt repos in: /etc/apt/sources.list.d/skype-stable.list
1: deb [arch=amd64] https://repo.skype.com/deb/ stable main
Active apt repos in: /etc/apt/sources.list.d/spotify.list
1: deb http://repository.spotify.com/ stable non-free
No active apt repos in: /etc/apt/sources.list.d/various.list
Info: Processes: 233 Uptime: 22m Memory: 3.75 GiB used: 1.69 GiB (45.0%) Init: SysVinit
v: 2.93 runlevel: 5 default: 5 Compilers: gcc: 8.3.0 alt: 8 Shell: bash v: 5.0.3
running in: quick-system-in inxi: 3.0.36
[/code]

Thanks.

docker: Cannot connect to host bodypix:9000 ssl:default [No address associated with hostname]

Thank you for putting this together, been looking for a solution for background on Ubuntu using video camera.

I setup the docker-compse.yml as directed in the DOCKER.md. When running docker-compose up -d I get the camera to show it's starting (blue light indicating camera in use) but looking at docker-compose logs I see the following. Is there additional changes needed?

Thank you,
Jim

`fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 151, in get_frame
fakecam_1  |     mask = await self._get_mask(frame, session)
fakecam_1  |   File "fake.py", line 65, in _get_mask
fakecam_1  |     async with session.post(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1012, in __aenter__
fakecam_1  |     self._resp = await self._coro
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 480, in _request
fakecam_1  |     conn = await self._connector.connect(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 523, in connect
fakecam_1  |     proto = await self._create_connection(req, traces, timeout)
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 858, in _create_connection
fakecam_1  |     _, proto = await self._create_direct_connection(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 971, in _create_direct_connection
fakecam_1  |     raise ClientConnectorError(req.connection_key, exc) from exc
fakecam_1  | aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host bodypix:9000 ssl:default [No address associated with hostname]
fakecam_1  | Mask request failed, retrying: Cannot connect to host bodypix:9000 ssl:default [No address associated with hostname]
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 964, in _create_direct_connection
fakecam_1  |     hosts = await asyncio.shield(self._resolve_host(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 829, in _resolve_host
fakecam_1  |     addrs = await \
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/resolver.py", line 29, in resolve
fakecam_1  |     infos = await self._loop.getaddrinfo(
fakecam_1  |   File "/usr/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
fakecam_1  |     return await self.run_in_executor(
fakecam_1  |   File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
fakecam_1  |     result = self.fn(*self.args, **self.kwargs)
fakecam_1  |   File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
fakecam_1  |     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
fakecam_1  | socket.gaierror: [Errno -5] No address associated with hostname
fakecam_1  | 
fakecam_1  | The above exception was the direct cause of the following exception:
fakecam_1  | 
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 151, in get_frame
fakecam_1  |     mask = await self._get_mask(frame, session)
fakecam_1  |   File "fake.py", line 65, in _get_mask
fakecam_1  |     async with session.post(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 1012, in __aenter__
fakecam_1  |     self._resp = await self._coro
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/client.py", line 480, in _request
fakecam_1  |     conn = await self._connector.connect(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 523, in connect
fakecam_1  |     proto = await self._create_connection(req, traces, timeout)
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 858, in _create_connection
fakecam_1  |     _, proto = await self._create_direct_connection(
fakecam_1  |   File "/usr/local/lib/python3.8/dist-packages/aiohttp/connector.py", line 971, in _create_direct_connection
fakecam_1  |     raise ClientConnectorError(req.connection_key, exc) from exc
fakecam_1  | aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host bodypix:9000 ssl:default [No address associated with hostname]

problems with running - opencv

I have tried to run python3 fake.py and I always get this error:

Cannot set camera property 3 to 1280, used value: 0.0
Cannot set camera property 4 to 720, used value: 0.0
Cannot set camera property 5 to 30, used value: 0.0
Running...
Please CTRL-C to reload the background / foreground images
Please CTRL-\ to exit
Traceback (most recent call last):
  File "fake.py", line 397, in <module>
    main()
  File "fake.py", line 393, in main
    loop.run_until_complete(cam.run())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "fake.py", line 282, in run
    await self.load_images()
  File "fake.py", line 176, in load_images
    background = cv2.resize(background, (self.width, self.height))
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-vu_aq9yd/opencv/modules/imgproc/src/resize.cpp:3932: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'

further ideas

Just some further ideas to test/implement (just limited by the CPU power):

  • merge the frontend images into a single .png file and use the transparent pixels as the mask
  • reduce the mask calculation by skipping some frames to improve overall performance, smooth the mask to prevent mask wobble (bodypix did not know where the mask was in the last frame, but fakecam does know it and might improve accuracy)
  • when more options are added it might be useful to make them configurable using parameters or a config file
  • Should I add a description howto use Android or ip-based webcams? There are other howtos around but most did not work out of the box with OpenCV (since it misses YUP12 support).
  • render the person(s) at the center of the screen (or make the position configurable):
    • get the dimension of the non-masked pixels from the original video stream using bodypix
    • keep it aligned at top or center to the configured position so that the head is not moving away from the speaker's desk
  • try to better fit the stream mask or reduce the hallow effect (how?)
  • add another (optional) root layer which can be sourced by another video source
    • video files or live stream could be easily provided as /dev/video device using ffmpeg so that we can use it from OpenCV
    • a background mask is required (or just support for .png files with alpha channels)
    • WHY? /me on the ISS in front for a window showing a live video looking at the earth from space with some spacecraft utils in the front - we just need to add a fake physics device powered by USB-C to get the zero gravity feeling ;-)

What do you think?

Missing CUDA libs and CPU fallback won't work

Hi there, first of all thank you for your work of putting this all together!

I have trouble getting it to a) run at all and b) to recognize my GPU or CUDA library.
I have a RTX 2060 and run Fedora 33. I installed tensorflow and cuda via miniconda: conda install -c conda-forge tensorflow-gpu. By conda is initialized but when I do node app.js
I get this:

Found a GPU at /dev/nvidia0
2021-02-14 10:00:48.113413: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-02-14 10:00:48.130389: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2894575000 Hz
2021-02-14 10:00:48.131143: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5606cc76cc10 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-02-14 10:00:48.131178: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-02-14 10:00:48.131739: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-02-14 10:00:48.146870: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-02-14 10:00:48.147212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce RTX 2060 major: 7 minor: 5 memoryClockRate(GHz): 1.35
pciBusID: 0000:01:00.0
2021-02-14 10:00:48.147329: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147370: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147397: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147434: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147457: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147500: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147529: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory
2021-02-14 10:00:48.147541: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-02-14 10:00:48.215818: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-02-14 10:00:48.215854: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0
2021-02-14 10:00:48.215865: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N

So it seems some missing CUDA libs are causing the tensorflow GPU package to fail but even the CPU fallback does not seem to work, because this is what I get when I am trying to run the pythono program (while the node process from above is still running):

base ❯ python fake.py                                                                                                                                                                                                             (base)
Cannot set camera property 3 to 1280, used value: 640.0
Cannot set camera property 5 to 30, used value: 10.0

--- Make sure the v4l2loopback kernel module is loaded ---
sudo modprobe v4l2loopback devices=1

Traceback (most recent call last):
  File "fake.py", line 425, in <module>
    main()
  File "fake.py", line 395, in main
    cam = FakeCam(
  File "fake.py", line 120, in __init__
    self.fake_cam = pyfakewebcam.FakeWebcam(v4l2loopback_path, self.width, self.height)
  File "/home/myuser/.local/lib/python3.8/site-packages/pyfakewebcam/pyfakewebcam.py", line 31, in __init__
    raise FileNotFoundError('device does not exist: {}'.format(video_device))
FileNotFoundError: device does not exist: /dev/video2

(I went down the akvcam path and installed that instead of v4l2loopback)
I tried your suggestion of removing the @tensorflow/tfjs-node-gpu entry from the package.json, cleaned and rebuild. But when I am not running it, I just get an error that that package is missing.

Any help is much appreciated!

npm missing from prerequisities (readme file)

Hello,
Thanks for this great work of art! I like it and it works really well!
I was just missing npm from the prerequisities in the readme file. It is obvious, but for some people maybe not.

fake.py freaks out when trying to access with chrome

Hi. Since I have no Webcam on my system I had to do a few more tricks. I'm using my DSLR as webcam via gphoto2 and v4l2loopback. So my modprobe looks like this

sudo modprobe v4l2loopback video_nr=0,2 exclusive_caps=1,1 card_label="EOS 7D mkII","Fake Webcam"
(Creating 2 devices, video0 and video2, each with exclusive_caps=1).

This way I can run the software without any changes. I can access both streams with VLC and everything runs fine.

BUT when I want to access the Webcams from google chrome (using jitsi for video chat), fake.py "freaks out". Seems, it can't get the mask anymore.

marco@schwipschwap:~/build/Linux-Fake-Background-Webcam/fakecam$ python3 fake.py -f 12
Running...
Please CTRL-C to reload the background / foreground images
Please CTRL-\ to exit
Mask request failed, retrying: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/resize.cpp:4045: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

Traceback (most recent call last):
  File "fake.py", line 106, in get_frame
    mask = await self._get_mask(frame, session)
  File "fake.py", line 56, in _get_mask
    frame = cv2.resize(frame, (0, 0), fx=self.scale_factor, fy=self.scale_factor)
cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/resize.cpp:4045: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

It's the same behaviour with or without the option "- f 12". That's just that my camera doesn't deliver more FPS over USB, so why should I waste a lot of processing power.

Tested jitsi with Firefox and there is no issue (but Jitsi is unbearably sluggish in firefox).

There are quite some people having issues accessing v4l2loopback "cameras" with chrome. But they normally just get "no picture" or "device not detected". But that chrome seems to be able to crash the video source seems really strange!

problems with tensorflow and node on fedora 32

i tried the same as oli and root

[root@DESKTOP-DM65VNV bodypix]# node app.js 
Found a GPU at /dev/nvidia0
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '@tensorflow/tfjs-node-gpu'
Require stack:
- /home/oli/Downloads/Linux-Fake-Background-Webcam/bodypix/app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at tensorflow (/home/oli/Downloads/Linux-Fake-Background-Webcam/bodypix/app.js:42:16)
    at Object.<anonymous> (/home/oli/Downloads/Linux-Fake-Background-Webcam/bodypix/app.js:3:12)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/oli/Downloads/Linux-Fake-Background-Webcam/bodypix/app.js' ]
}

[Docker GPU] Error in fakecam when running container

When running the container for fakecam, I get the following error:

Cannot set camera property 3 to 1280, used value: 640.0
Cannot set camera property 4 to 720, used value: 480.0
Traceback (most recent call last):
  File "fake.py", line 397, in <module>
    main()
  File "fake.py", line 368, in main
    cam = FakeCam(
  File "fake.py", line 118, in __init__
    self.fake_cam = pyfakewebcam.FakeWebcam(v4l2loopback_path, self.width, self.height)
  File "/usr/local/lib/python3.8/dist-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

Any guidance from here? I leave below the command I used to run the container:

docker run -d \
   --name=fakecam \
  --network=fakecam \
  --device=/dev/video0:/dev/video0 \
  --device=/dev/video1:/dev/video2 \
  -v fakecam:/socket \
  fakecam \
  -B /socket/bodypix.sock --no-foreground --scale-factor 1

Thanks in advance, the repository looks pretty cool! ^^

ValueError: operands could not be broadcast together with shapes

fakecam_1  | Please CTRL-C to reload the background and foreground images
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 108, in <module>
fakecam_1  |     frame = get_frame(cap, background)
fakecam_1  |   File "fake.py", line 93, in get_frame
fakecam_1  |     frame[:,:,c] = frame[:,:,c] * mask + background[:,:,c] * (1 - mask)
fakecam_1  | ValueError: operands could not be broadcast together with shapes (720,1280) (480,640)

I get this error with and without docker.

Animated image load failure

Dont think this is a failure with this app specifically, but having followed the README, I have the system working with static jpg images. I can change them out, and am successfully able to use all other command switches. However whenever I use the -b and point to gif, or webm, or webp the application kicks up an OpenCV error.

Any suggestions on how I can debug this further?
chubbard@guyver-office:~/160_ssd/Linux-Fake-Background-Webcam/fakecam$ python3 fake.py -v /dev/video20 -B http://127.0.0.1:9001 --no-foreground -b /home/chubbard/Pictures/anime_girl.webp
Cannot set camera property 3 to 1280, used value: 640.0
Cannot set camera property 5 to 30, used value: 7.5
Running...
Please CTRL-C to reload the background / foreground images
Please CTRL-\ to exit
[ERROR:0] global /io/opencv/modules/videoio/src/cap.cpp (116) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.2.0) /io/opencv/modules/videoio/src/cap_images.cpp:293: error: (-215:Assertion failed) !_filename.empty() in function 'open'

Traceback (most recent call last):
File "fake.py", line 397, in
main()
File "fake.py", line 393, in main
loop.run_until_complete(cam.run())
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "fake.py", line 297, in run
frame = await self.mask_frame(session, frame)
File "fake.py", line 260, in mask_frame
background_frame = next(self.images["background"])
File "fake.py", line 202, in next_frame
self.bg_video_adv_rate = round(self.bg_video_fps/self.current_fps)
ZeroDivisionError: float division by zero

Mask request failed

Thanks for this, I was keen to try it out.

I get the following from the fakecam image:

mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
mask request failed, retrying
Traceback (most recent call last):
  File "fake.py", line 69, in <module>
    frame = get_frame(cap, background_scaled)
  File "fake.py", line 50, in get_frame
    frame[:,:,c] = frame[:,:,c]*mask + background_scaled[:,:,c]*inv_mask
ValueError: operands could not be broadcast together with shapes (720,1280) (480,640) 

Looks like a mismatch between resolutions or similar?

Python no module even when it's installled

Running like: sudo python3 fake.py -B ./back.mp4 -W /dev/video0 or just like sudo python3 -u fake.py leads to:

Traceback (most recent call last):   File "fake.py", line 17, in <module>     import requests_unixsocket ModuleNotFoundError: No module named 'requests_unixsocket'

However,

[sw@t490s fakecam]$ python3 -m pip install requests
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in /home/sw/.local/lib/python3.8/site-packages (2.23.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.8/site-packages (from requests) (2020.6.20)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3.8/site-packages (from requests) (1.25.9)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.8/site-packages (from requests) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/lib/python3.8/site-packages (from requests) (3.0.4)

Can you lead me what to check?

Thanks

OSError: [Errno 22] Invalid argument

Hello, I kinda need some help to try to fix my problem. I'm always getting the following error while trying to run fake.py

python3 fake.py -w /dev/video2
Cannot set camera property 3 to 1280, used value: 640.0
Cannot set camera property 5 to 30, used value: 10.0
Traceback (most recent call last):
  File "fake.py", line 397, in <module>
    main()
  File "fake.py", line 368, in main
    cam = FakeCam(
  File "fake.py", line 118, in __init__
    self.fake_cam = pyfakewebcam.FakeWebcam(v4l2loopback_path, self.width, self.height)
  File "/home/basti/.local/lib/python3.8/site-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

I don't think this is a duplicate of #68 as I tried every possible video device and it seems to load some values at the beginning.
I installed like mentioned on the github page. I'm using v4l2loopback, but already tried akvcam with no success.

tfjs_binding.node not found, following instructions does nothing

I'm trying to set up on a Debian Buster system using Intel graphics. Here's what happens when I try to start the app:

carlf@debian-NUCi5:~/Linux-Fake-Background-Webcam/bodypix$ nodejs app.js
No GPU found at /dev/nvidia0, using CPU
/home/carlf/Linux-Fake-Background-Webcam/bodypix/node_modules/@tensorflow/tfjs-node/dist/index.js:49
throw new Error("The Node.js native addon module (tfjs_binding.node) can not "
^

Error: The Node.js native addon module (tfjs_binding.node) can not be found at path: /home/carlf/Linux-Fake-Background-Webcam/bodypix/node_modules/@tensorflow/tfjs-node/lib/napi-v5/tfjs_binding.node.
Please run command 'npm rebuild @tensorflow/tfjs-node build-addon-from-source' to rebuild the native addon module.
If you have problem with building the addon module, please check https://github.com/tensorflow/tfjs/blob/master/tfjs-node/WINDOWS_TROUBLESHOOTING.md or file an issue.
at Object. (/home/carlf/Linux-Fake-Background-Webcam/bodypix/node_modules/@tensorflow/tfjs-node/dist/index.js:49:11)
at Module._compile (internal/modules/cjs/loader.js:1236:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
at Module.load (internal/modules/cjs/loader.js:1085:32)
at Function.Module._load (internal/modules/cjs/loader.js:950:14)
at Module.require (internal/modules/cjs/loader.js:1125:19)
at require (internal/modules/cjs/helpers.js:75:18)
at tensorflow (/home/carlf/Linux-Fake-Background-Webcam/bodypix/app.js:45:16)
at Object. (/home/carlf/Linux-Fake-Background-Webcam/bodypix/app.js:3:12)
at Module._compile (internal/modules/cjs/loader.js:1236:30)

When I try to follow the instructions about compiling the missing module, that fails. I am not familiar at all with node.js and only very slightly with JavaScript, so I can't debug the resulting errors. The output is fairly long, so I captured it with script and I am uploading the typescript as an attachment to this report. The upshot is that compilation fails.

I do notice the line:

In file included from ../binding/tfjs_backend.cc:18:
../binding/tfjs_backend.h:26:10: fatal error: tensorflow/c/eager/c_api.h: No such file or directory

However, locate tensorflow | grep c_api results in:
carlf@debian-NUCi5:~/Linux-Fake-Background-Webcam/bodypix$ locate tensorflow | grep c_api
/home/carlf/Linux-Fake-Background-Webcam/bodypix/node_modules/@tensorflow/tfjs-node/deps/include/tensorflow/c/c_api.h
/home/carlf/Linux-Fake-Background-Webcam/bodypix/node_modules/@tensorflow/tfjs-node/deps/include/tensorflow/c/c_api_experimental.h

Is the script looking in the wrong place? The file is on my system but not in the directory mentioned in the error message.

Thank you. I hope to eventually be able to try your seemingly-wonderful creation.
typescript.txt

add a foreground image

After you have updated the background image I think we also need a foreground image. The foreground image needs to support alpha channel (.png?) and could be used to get the illusion of a speaker's desk. What did you think?

Port 9000

I'm using Docker portainer.io with port 9000.

In this case I cannot use LFBW at port 9000, too. Even I have to stop portainer.io.

Using export PORT=9011 I can see with netstat -l | grep 9011that somebody will hear at this port. But I get no video from my fakecam device. Even port 9000 is free or not.

Using a local path I habe the same effect.

Any other suggestions?

device does not exist: /dev/video20

I'm using the docker setup, and followed the instructions but getting this message:

2020-05-04 22:55:18.833160: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64
bodypix_1 | 2020-05-04 22:55:18.833172: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
bodypix_1 | 2020-05-04 22:55:18.833210: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (OptiPlex-9020): /proc/driver/nvidia/version does not exist
fakecam_1 |
fakecam_1 | --- Make sure the v4l2loopback kernel module is loaded ---
fakecam_1 | sudo modprobe v4l2loopback devices=1
fakecam_1 |
fakecam_1 | Traceback (most recent call last):
fakecam_1 | File "fake.py", line 77, in
fakecam_1 | fake = pyfakewebcam.FakeWebcam('/dev/video20', width, height)
fakecam_1 | File "/usr/local/lib/python3.8/site-packages/pyfakewebcam/pyfakewebcam.py", line 31, in init
fakecam_1 | raise FileNotFoundError('device does not exist: {}'.format(video_device))
fakecam_1 | FileNotFoundError: device does not exist: /dev/video20

/dev/video2 has 777 permissions

this is the output of v4l2-ctl --list-devices:
v4l2loopback (platform:v4l2loopback-000):
/dev/video2

HD Pro Webcam C920 (usb-0000:00:14.0-10):
/dev/video0
/dev/video1

Notice that I don't have nvidia video card, is that needed?

Performance issues on docker CPU builds

Hi, I've been using Linux-Fake-Background-Webcam with docker-compose for a while and noticed a huge performance drop since 05ed29f. I'm using a .mov video background and no foreground. Any docker builds since that commit run at less than 1fps.
Steps I use to build older but faster version:

git checkout -b old-release 05ed29fedc695718528e5ababf402a973db6bd01
# edit docker-compose.yml as needed
docker-compose up --build

I'm running Ubuntu 18.04 with kernel 5.4.0-42-generic on an Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz

scale and place camera input in frame

It would be neat if we could scale the camera input and place it somewhere in the frame. This would allow a 2 things.

  1. when using the default background I show up huge behind the podium. Being able to scale my image there (making me smaller) would make me the appropriate size for the background

  2. (arguably the more important point) being able to scale and place the camera input somewhere specific in the frame and using your hologram filter would allow people to use this as a background, which I think is probably the most important work anyone could do :)

I'm not super familiar with the code and I know a little python, so I could give this a shot with some pointers.

ModuleNotFoundError: No module named 'pyfakewebcam'

Hi, i've had follow the steps, but unfortunatelly by my lack of knowledge i don't know what i did wrong to get this error:

$ python3 fake.py
Traceback (most recent call last):
  File "fake.py", line 12, in <module>
    import pyfakewebcam
ModuleNotFoundError: No module named 'pyfakewebcam'

I may be silly, but I really don't know what to do.

Using python instead of nodejs for grabbing webcam frames

I read the blog post and saw your project and as I did not want to setup docker and run nodejs, I looked for projects that use bodypix in python and found https://github.com/ajaichemmanam/simple_bodypix_python.

I created a fork and combined their example script with your webcam script and created this repo: https://github.com/allo-/simple_bodypix_python

The program already works, but has a few issues like a worse resolution (I need to investigate how the node module interpolates the mask in such a high resolution).

Would you like to work together?

[bodypix] Fall back to CPU when GPU does not have CUDA support

I followed the installation instructions and noticed tensorflow import errors relating to lib cuda:

node app.js 
Found a GPU at /dev/nvidia0
2020-07-17 06:59:53.202413: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-17 06:59:53.385177: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3593130000 Hz
2020-07-17 06:59:53.385712: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5fe7d20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-17 06:59:53.385757: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-07-17 06:59:53.425874: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-07-17 06:59:53.473448: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-17 06:59:53.473844: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1660 SUPER major: 7 minor: 5 memoryClockRate(GHz): 1.815
pciBusID: 0000:01:00.0
2020-07-17 06:59:53.473915: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.473950: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.473983: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.474014: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.474045: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.474076: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.474107: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory
2020-07-17 06:59:53.474114: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-07-17 06:59:53.669383: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-17 06:59:53.669412: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2020-07-17 06:59:53.669417: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
^C

Upon further inspection, it seems my GPU (GeForce GTX 1660 SUPER) doesn't support CUDA which would explain why the importing fails. The readme states this works off the CPU as well, would it be possible to check the GPU for CUDA compatibility in addition to the presence of /dev/nvidia0?

docker-compose error on akvcam

I'm not using akvcam, i'm using v4l2loopback

Starting linux-fake-background-webcam_bodypix_1 ... done
Starting linux-fake-background-webcam_fakecam_1 ... done
Attaching to linux-fake-background-webcam_bodypix_1, linux-fake-background-webcam_fakecam_1
bodypix_1  | 2020-06-08 05:02:52.808669: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
bodypix_1  | 2020-06-08 05:02:52.884177: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3293975000 Hz
bodypix_1  | 2020-06-08 05:02:52.884603: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5d3c250 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
bodypix_1  | 2020-06-08 05:02:52.884633: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
fakecam_1  | Traceback (most recent call last):
fakecam_1  |   File "fake.py", line 22, in <module>
fakecam_1  |     from akvcam import AkvCameraWriter
fakecam_1  | ModuleNotFoundError: No module named 'akvcam'
linux-fake-background-webcam_fakecam_1 exited with code 1

Background Image But No Webcam

I can't get v4l2loopoback to connect to my actual webcam, which should be /dev/video5 and /dev/video6 according to:

v4l2-ctl --list-devices

How do I get it to use my webcam? I'm not sure why it lists two.

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.