Coder Social home page Coder Social logo

pandinosaurus / pyfakewebcam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from em-lopez/pyfakewebcam

0.0 0.0 0.0 221 KB

A library for writing RGB frames to a fake webcam device on Linux!

License: GNU Lesser General Public License v3.0

Python 100.00%

pyfakewebcam's Introduction

pyfakewebcam

An API for writing RGB frames to a fake webcam device on Linux!

Compatible with Python2.7 and Python3.x

Author: John Emmons
Email: [email protected]

installation

# use pip to get the latest stable release
pip install pyfakewebcam

# use git to install the latest version
git clone https://github.com/jremmons/pyfakewebcam.git
cd pyfakewebcam
python setup.py install

dependencies

# python 
pip install numpy

# linux
apt-get install v4l2loopback-utils

# linux (optional)
apt-get install python-opencv # 10x performance improvement if installed (see below)
apt-get install ffmpeg # useful for debugging

performance

When I run the examples/example.py script (640x360 resolution) on an Intel i7-3520M (2.9GHz, turbos to 3.6 GHz), the time to schedule a single frame is ~3 milliseconds (with opencv installed). You can use this library without installing opencv, but it is almost 10x slower; time to schedule a frame without opencv is ~26 milliseconds (RGB to YUV conversion done with numpy operations).

If your goal is to run at 30Hz (or slower) and ~26 milliseconds of delay is acceptable in your application, then opencv may not be necessary.

usage

Insert the v4l2loopback kernel module.

modprobe v4l2loopback devices=2 # will create two fake webcam devices

Example code.

# see red_blue.py in the examples dir
import time
import pyfakewebcam
import numpy as np

blue = np.zeros((480,640,3), dtype=np.uint8)
blue[:,:,2] = 255

red = np.zeros((480,640,3), dtype=np.uint8)
red[:,:,0] = 255

camera = pyfakewebcam.FakeWebcam('/dev/video1', 640, 480)

while True:

    camera.schedule_frame(red)
    time.sleep(1/30.0)

    camera.schedule_frame(blue)
    time.sleep(1/30.0)

Run the following command to see the output of the fake webcam.

ffplay /dev/video1

pyfakewebcam's People

Contributors

jremmons avatar em-lopez avatar

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.