{"id":13472334,"url":"https://github.com/likeablob/rpi-wfh-webcam","last_synced_at":"2025-03-26T15:31:56.532Z","repository":{"id":127233236,"uuid":"254634323","full_name":"likeablob/rpi-wfh-webcam","owner":"likeablob","description":"A \"smart\" USB webcam which hides your room","archived":false,"fork":false,"pushed_at":"2023-11-13T22:34:55.000Z","size":914,"stargazers_count":19,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T04:13:39.903Z","etag":null,"topics":["bodypix","opencv","raspberry-pi","tensorflow","webcam","wfh"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/likeablob.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-10T12:54:47.000Z","updated_at":"2024-08-24T13:46:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"4950a1d4-8de7-4390-ad35-e727c4a9810c","html_url":"https://github.com/likeablob/rpi-wfh-webcam","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likeablob%2Frpi-wfh-webcam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likeablob%2Frpi-wfh-webcam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likeablob%2Frpi-wfh-webcam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likeablob%2Frpi-wfh-webcam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/likeablob","download_url":"https://codeload.github.com/likeablob/rpi-wfh-webcam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245681421,"owners_count":20655189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bodypix","opencv","raspberry-pi","tensorflow","webcam","wfh"],"created_at":"2024-07-31T16:00:53.866Z","updated_at":"2025-03-26T15:31:56.114Z","avatar_url":"https://github.com/likeablob.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg align=\"center\" width=\"300px\" height=\"auto\" src=\"./assets/spam_s.gif\"\u003e\n\u003c/p\u003e\n\n# A \"smart\" USB webcam which hides your room well.\n\n- Q. Why do you need this?\n  - A. Because my man cave is too messy to have video meetings.\n- Q. Why don't you use \u003cSOFTWARE_NAME_HERE\u003e  (e.g. Snap Camera)?\n  - A. Because our IT dept. does not allow us to be root.\n- Q. My IT dept. does not allow to use any unauthorized usb device.\n  - A. Clean up your room.\n\nThanks to [[ajaichemmanam]'s great work](https://github.com/ajaichemmanam/simple_bodypix_python) on porting [tensorflow-js/body-pix](https://github.com/tensorflow/tfjs-models/tree/master/body-pix)\n ([Please see their jaw-dropping live demo if you miss it.](https://storage.googleapis.com/tfjs-models/demos/body-pix/index.html)) to Python, \n an idea came to me that combining BodyPix and g_webcam to hide my messy room while working from home.\n\n## Prerequisites\n- Raspberry Pi 4 (Pi3 or other SBCs may work too.)\n- USB Webcam (or RPi Camera Module)\n- Jailed laptop provided by the IT dept.\n\n## Data flow\n[![](https://mermaid.ink/img/eyJjb2RlIjoiZ3JhcGggTFJcbiAgICBzdWJncmFwaCBSYXNwYmVycnkgUGlcbiAgICAgICAgdmlkW1wiL2R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LR\n    subgraph Raspberry Pi\n        vid[\"/dev/videoN\"] --\u003e app\n        img[Image/Video file] --\u003e app\n        app[\"app.py\u003cbr\u003e(OpenCV + TensorFlow)\"] --\u003e ffmpeg\n        ffmpeg[ffmpeg] --\u003e v4l2l\n        v4l2l[v4l2loopback] --\u003e gw[\"g_webcam \u003cbr/\u003e(+uvc-gadget)\"]\n    end\n    subgraph PC\n        gw --\u003e |USB|sw[Teams, Slack, etc.]\n    end\n```\n\n## Setup steps\n### Download models\n```bash\n$ cd path/to/cloned/repo\n$ pipenv install -d\n$ pipenv run ./get-model.sh bodypix/mobilenet/float/050/model-stride16\n$ ls -hl bodypix_mobilenet_float_050_model-stride16.pb\n```\n- See https://storage.googleapis.com/tfjs-models for other models\n\n### Test run on your laptop\n```bash\n# Show the usage help\n$ pipenv run start -h \n# Start app.py with -g to show results visually\n$ pipenv run start -m bodypix_mobilenet_float_050_model-stride16.pb -g\n\n# Tips 1: Change the background image\n$ pipenv run start -m bodypix_mobilenet_float_050_model-stride16.pb -g -i awesome_image.jpg\n# Tips 2: Change the background video\n$ pipenv run start -m bodypix_mobilenet_float_050_model-stride16.pb -g -e awesome_video.mp4\n```\n\n## Install to RPi\n- Copy all the files including models to RPi.\n```bash\n$ rsync -avP ../rpi-wfh-webcam rpi4:/home/pi/\n```\n\n- To install TensorFlow on your Pi4, refer to https://qengineering.eu/install-tensorflow-2.1.0-on-raspberry-pi-4.html .\n```bash\n# Install the dependencies\n$ sudo pip3 install opencv-python pillow pafy youtube-dl\n$ sudo apt install v4l2loopback-dkms v4l2loopback-utils ffmpeg\n\n# Enable the required modules \u0026 overlay\n$ sudo vi /boot/config.txt\ndtoverlay=dwc2 # Append to the last line\n\n$ sudo vi /etc/rc.local\nmodprobe v4l2loopback\nmodprobe dwc2\nmodprobe uvcvideo\nsleep 3 # FIXME: Ugly hack to avoid crashes\nmodprobe g_webcam\n\n# Reboot the device\n$ sudo reboot now\n\n# Check the mappings of video devices\n$ v4l2-ctl --list-devices                                             \nfe980000.usb (gadget):\n        /dev/video3\n\nbcm2835-codec-decode (platform:bcm2835-codec):\n        /dev/video10\n        /dev/video11\n        /dev/video12\n\nDummy video device (0x0000) (platform:v4l2loopback-000):\n        /dev/video0\n\nUSB 2.0 Camera: HD USB Camera (usb-0000:01:00.0-1.4):\n        /dev/video1\n        /dev/video2\n\n# Lanch app.py and pipe the video stream to /dev/video0 by using ffmpeg.\n# Also we use ffmpeg to resize the stream to 1280x720.\n./app.py -m bodypix_mobilenet_float_050_model-stride16.pb -c 1 | ffmpeg -s 640x480 -f rawvideo -pix_fmt bgr24 -framerate 10 -i - -s 1280x720 -vf crop=w=640:h=360 -r 10 -f v4l2 -vcodec rawvideo -pix_fmt yuyv422 /dev/video0\n\n# Then enable the webcam\n./uvc-gadget.armv7 -f 0 -r 1 -u /dev/video3 -v /dev/video0\n```\n- On your laptop. Visit [WebRTC samples](https://webrtc.github.io/samples/src/content/getusermedia/resolution/) to check the video stream works.\n\n## TODO\n- [ ] Make a docker image for easier installation.\n- [ ] Support .tflite to use Google Coral accelerator.\n- [ ] It might be possible to override `getUserMedia()` to inject a processed video stream? (Oh, we don't need any Pi.)\n\n## Acknowledgements\n- [`bg.jpg`](./bg.jpg): Photo by Elizeu Dias on Unsplash\n- tensorflow/tfjs-models: https://github.com/tensorflow/tfjs-models/tree/master/body-pix\n- _[wlhe]_'s `uvc-gadget`: https://github.com/wlhe/uvc-gadget\n- _[ajaichemmanam]_'s `simple_bodypix_python`: https://github.com/ajaichemmanam/simple_bodypix_python\n- Thanks [_[jtsymon]_](https://github.com/jtsymon), for [your contributions](https://github.com/likeablob/rpi-wfh-webcam/pulls?q=is%3Apr+author%3Ajtsymon).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flikeablob%2Frpi-wfh-webcam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flikeablob%2Frpi-wfh-webcam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flikeablob%2Frpi-wfh-webcam/lists"}