GithubHelp home page GithubHelp logo

back-pack-jack / hello-websocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmlaker/hello-websocket

0.0 0.0 0.0 89 KB

Webcam over WebSocket in Python using OpenCV and Tornado

License: MIT License

Python 62.54% Makefile 17.16% HTML 20.30%

hello-websocket's Introduction

hello-websocket

Webcam over websocket in Python using OpenCV and Tornado.

How it works

A recorder process continuously reads images from a webcam. Upon every capture, it writes the image to a Redis key-value store.

A separate server process (running Tornado) handles websocket requests sent by a client (web browser). Upon receiving a request, it retrieves the latest image from the Redis database and sends it to the client over the established websocket connection.

https://github.com/vmlaker/hello-websocket/blob/master/diagram.png?raw=true

The client web page is dead simple: It sends an initial request on a websocket. When image data arrives, it assigns it to src attribute of the <img> tag, then simply sends the next request. That's it!

Installation

The code uses Python in a virtualenv. Since OpenCV is not officially in the Python Package Index, we manually copy the system OpenCV library into the virtualenv.

First, install OpenCV for Python system-wide:

apt-get install python-opencv

Also install Redis server:

apt-get install redis-server

Build the virtual environment with all needed modules:

make

Usage

Two separate programs need to be running: 1) the recorder which captures and writes to Redis database, and 2) the server which reads the current image from the database and serves to requesting WebSocket clients.

Run the recorder:

make recorder

Now (in a different shell) run the server:

make server

Go to http://localhost:9000 to view the webcam.

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.