allo- / virtual_webcam_background

Use a virtual webcam background and overlays with body-pix and v4l2loopback
GNU General Public License v3.0
306 stars 47 forks source link

Pip vs. pip3 #53

Closed 7wells closed 1 year ago

7wells commented 3 years ago

Hello!

Depending on which Python version is installed, the commend needs to be 'pip3' instead of just 'pip', i.e.: pip3 install -r requirements.txt

With just 'pip' it did not work for my on Raspbian OS. Thanks for your ind consideration, and please accept my apologies if this is maybe not the right place to mention this.

allo- commented 3 years ago

In a virtual environment built for python3 you should probably have a pip binary, which is the same as pip3. But we could add a note. Would you like to create a pull request for a note in the readme?

Do you use the program on a Raspberry Pi? I would have thought it is probably too slow for a Pi.

7wells commented 3 years ago

Yes, you are right, of course. And sorry, but I am not familiar with pull requests. Yes, I tried this on a RPi 2 but have meanwhile abondoned it, because I was unable to sort things about dependencies. Please accept my sincerest apologies for bothering you and the community, but I will not further pursue this for the time being. But I would like to thank you for this very interesting and helpful project. If I have a better understanding of getting things up and running (maybe on another device), I will happily come back. 😊

allo- commented 3 years ago

Reporting bugs and suggestions is always welcome.

bard83 commented 3 years ago

I've changed the pip install -r requirements.txt to pip3 install -r requirements.txt because I had error installing numpy=1.18.5. Still got error.

OS: Ubuntu 18.04

bard83@bard83-ThinkPad-E570:~/virtual_webcam_background$ pip install -r requirements.txt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting tensorflow
  Using cached tensorflow-2.1.0-cp27-cp27mu-manylinux2010_x86_64.whl (421.8 MB)
ERROR: Could not find a version that satisfies the requirement numpy==1.18.5 (from -r requirements.txt (line 2)) (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.3, 1.10.4, 1.11.0b3, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.11.1rc1, 1.11.1, 1.11.2rc1, 1.11.2, 1.11.3, 1.12.0b1, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.1rc1, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 1.13.3, 1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6)
ERROR: No matching distribution found for numpy==1.18.5 (from -r requirements.txt (line 2))
bard83@bard83-ThinkPad-E570:~/virtual_webcam_background$ pip3 install -r requirements.txt
Collecting tensorflow (from -r requirements.txt (line 1))
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/de/f0/96fb2e0412ae9692dbf400e5b04432885f677ad6241c088ccc5fe7724d69/tensorflow-1.14.0-cp36-cp36m-manylinux1_x86_64.whl (109.2MB)
    100% |████████████████████████████████| 109.2MB 13kB/s 
Collecting numpy==1.18.5 (from -r requirements.txt (line 2))
  Cache entry deserialization failed, entry ignored
  Using cached https://files.pythonhosted.org/packages/b3/a9/b1bc4c935ed063766bce7d3e8c7b20bd52e515ff1c732b02caacf7918e5a/numpy-1.18.5-cp36-cp36m-manylinux1_x86_64.whl
Collecting scipy (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/c8/89/63171228d5ced148f5ced50305c89e8576ffc695a90b58fe5bb602b910c2/scipy-1.5.4-cp36-cp36m-manylinux1_x86_64.whl (25.9MB)
    100% |████████████████████████████████| 25.9MB 44kB/s 
Collecting pillow (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/b6/c0/442d9d87e0da00bf856ef6dd4916f84a2d710b5f1a367d42d7f3c4e99a6c/Pillow-8.1.0-cp36-cp36m-manylinux1_x86_64.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 597kB/s 
Collecting pyyaml (from -r requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/7a/5b/bc0b5ab38247bba158504a410112b6c03f153c652734ece1849749e5f518/PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl (640kB)
    100% |████████████████████████████████| 645kB 1.7MB/s 
Collecting pyfakewebcam (from -r requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/ce/8b/0bb1984cf716d7b4825a1480f77e71441d39ffebb158ccce5e95ce17eec9/pyfakewebcam-0.1.0.tar.gz
Collecting opencv-python (from -r requirements.txt (line 7))
  Downloading https://files.pythonhosted.org/packages/bb/08/9dbc183a3ac6baa95fabf749ddb531bd26256edfff5b6c2195eca26258e9/opencv-python-4.5.1.48.tar.gz (88.3MB)
    100% |████████████████████████████████| 88.3MB 15kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-pd1laeao/opencv-python/setup.py", line 10, in <module>
        import skbuild
    ModuleNotFoundError: No module named 'skbuild'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-pd1laeao/opencv-python/
allo- commented 3 years ago

Can you try

pip3 install numpy==1.18.5

Does this work for you?

This works here, even when 1.19.5 is available. You can also try to change the required version number, but 1.18.x is tested (1.19.x will probably work, but is not tested yet).

bard83 commented 3 years ago

I don't know if I get correctly. I've tried

pip3 install numpy==1.18.5
pip3 install -r requirements.txt

and I've got the same output shown above. Which has been solved (works only for pip3) upgrading pip and pip3.

pip install --upgrade pip
pip3 install --upgrade pip

I got pip3 install -r requirements.txt working and also ./getModels.sh. Now I've a blocker on the modprobe operation:

$ modprobe v4l2loopback exclusive_caps=1 video_nr=2 # creates /dev/video2
modprobe: ERROR: could not insert 'v4l2loopback': Operation not permitted

$ ls -l /dev | grep video
crw-rw----  1 root video      29,     0 Jan 27 10:06 fb0
crw-rw----  1 root video     240,     0 Jan 27 10:06 media0
crw-rw----+ 1 root video      81,     0 Jan 27 10:06 video0

should it be executed using sudo?

allo- commented 3 years ago

Yes. You need to be root and your user needs to be in the group video.

bard83 commented 3 years ago

Probably I've miss understood the installation guide on the web page (or don't know if it's a bit missleading). But I guess that now I've configured it. Still not working but the error seems to be a bit different:

$ ./run.sh
2021-01-27 16:48:14.757352: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-01-27 16:48:14.757381: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Reloading config.
2021-01-27 16:48:15.903117: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-01-27 16:48:15.903159: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2021-01-27 16:48:15.903188: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (bard83-ThinkPad-E570): /proc/driver/nvidia/version does not exist
Failed to reduce capture buffer size. Latency will be higher!
Model: mobilenet (multiplier=0.5, stride=16)
Loading model...
2021-01-27 16:48:15.944100: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-01-27 16:48:15.971610: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2699905000 Hz
2021-01-27 16:48:15.971983: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x402d600 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-01-27 16:48:15.972022: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-01-27 16:48:16.001567: W tensorflow/core/common_runtime/graph_constructor.cc:1529] Importing a graph with a lower producer version 38 into an existing graph with producer version 440. Shape inference will have run different parts of the graph with different producer versions.
2021-01-27 16:48:16.036284: I tensorflow/core/grappler/devices.cc:69] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2021-01-27 16:48:16.036419: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2021-01-27 16:48:16.070930: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816] Optimization results for grappler item: graph_to_optimize
2021-01-27 16:48:16.070960: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   debug_stripper: debug_stripper did nothing. time = 0.018ms.
2021-01-27 16:48:16.070969: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   remapper: Graph size after: 244 nodes (0), 171 edges (0), time = 0.721ms.
2021-01-27 16:48:16.070977: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   constant_folding: Graph size after: 172 nodes (-72), 171 edges (0), time = 7.693ms.
2021-01-27 16:48:16.070983: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   arithmetic_optimizer: Graph size after: 172 nodes (0), 171 edges (0), time = 3.838ms.
2021-01-27 16:48:16.070990: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   dependency_optimizer: Graph size after: 172 nodes (0), 171 edges (0), time = 1.183ms.
2021-01-27 16:48:16.070996: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   debug_stripper: debug_stripper did nothing. time = 0.119ms.
2021-01-27 16:48:16.071002: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   remapper: Graph size after: 172 nodes (0), 171 edges (0), time = 0.477ms.
2021-01-27 16:48:16.071008: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   constant_folding: Graph size after: 172 nodes (0), 171 edges (0), time = 2.915ms.
2021-01-27 16:48:16.071015: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   arithmetic_optimizer: Graph size after: 172 nodes (0), 171 edges (0), time = 3.286ms.
2021-01-27 16:48:16.071021: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:818]   dependency_optimizer: Graph size after: 172 nodes (0), 171 edges (0), time = 1.537ms.
done.
Traceback (most recent call last):
  File "./virtual_webcam.py", line 143, in <module>
    layers = reload_layers(config)
  File "./virtual_webcam.py", line 52, in reload_layers
    layers.append((layer_type, filters.get_filters(config, layer_filters)))
  File "/home/bard83/virtual_webcam_background/filters/__init__.py", line 40, in get_filters
    *_args, **_kwargs))
  File "/home/bard83/virtual_webcam_background/filters/images.py", line 53, in __init__
    self.reload_image()
  File "/home/bard83/virtual_webcam_background/filters/images.py", line 57, in reload_image
    self.width, self.height, self.interpolation_method)
  File "/home/bard83/virtual_webcam_background/filters/images.py", line 30, in reload_images
    interpolation=_interpolation_method)
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-7m_g9lbm/opencv/modules/imgproc/src/resize.cpp:4054: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'
bard83 commented 3 years ago

form the web page:

virtualenv -p python3.7 ~/venvs/virtual_webcam
source ~/venv/virtual_webcam/bin/activate
pip install -r requirements.txt
./get-model.sh

The source command points to the wrong path an s is missing in venv folder.

allo- commented 3 years ago

Can you try a configuration without any filters? Or add a print((width, height)) line.

The error looks like one of the two problems:

You can also specify an own resolution in the config file

width: 640
height: 480

Should work with almost every camera.

allo- commented 3 years ago

The source command points to the wrong path an s is missing in venv folder.

Thank you, I fixed it.

bard83 commented 3 years ago

my config.yml

segmentation_threshold: 0.75
blur: 5
erode: 15
dilate: 10
virtual_video_device: "/dev/video2"
real_video_device: "/dev/video1"
width: 1280
height: 720
segmentation_threshold: 0.75
average_masks: 2
mjpeg: False
layers:
  - "input": [["blur", 10]]
  - "foreground": []
  - "previous": [["image", "./images/fog.png"], ["roll", 5, 0]]
allo- commented 3 years ago

Is video1 correct or should it be video0?

bard83 commented 3 years ago

values have been reversed. I should suppose that it is working.

segmentation_threshold: 0.75
blur: 5
erode: 15
dilate: 10
virtual_video_device: "/dev/video1"
real_video_device: "/dev/video2"
width: 1280
height: 720
segmentation_threshold: 0.75
average_masks: 2
mjpeg: False
layers:
  - "input": [["blur", 10]]
  - "foreground": []
  - "previous": [["image", "./images/fog.png"], ["roll", 5, 0]]
$ ./run.sh
2021-01-27 17:01:30.068619: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-01-27 17:01:30.068653: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Reloading config.
2021-01-27 17:01:31.601284: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-01-27 17:01:31.601312: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2021-01-27 17:01:31.601336: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (bard83-ThinkPad-E570): /proc/driver/nvidia/version does not exist
allo- commented 3 years ago

When you got no futher output it probably now works, but something is strange with the numbers of your video devices.

With the program qv4l2 you should be able to see details about your cameras (and for example zoom the real camera). It should show "loopback" as input for the v4l2loopback device and "Camera 1" for the real device.

And you can test the video with vlc or mplayer and opening "tv://". You may not be able to open the real device as long as the virtual_webcam program is running and playing from the virtual device usually pauses when you stop the program or the config is reloaded.

This gets off-topic here, but I write it down because we probably could update the documentation to explain a bit more.

bard83 commented 3 years ago

thanks, with qv4l2 i've checked my camera and yes, my configuration was wrong. This should be the correct one:

virtual_video_device: "/dev/video2"
real_video_device: "/dev/video0"

Screenshot from 2021-01-27 19-16-22

I'll open a new issue with the error that I've got with the new configuration. Thanks.