6

I am working on a face recognition project using Flask as my web server running on a Ubuntu 14.04 Machine. I am using OpenCV 2.4.9 as my image processing software which is written using Python2.7. I would like to be able to access a clients webcam through their browser to capture a image or frame from the webcam stream and send it back to the server to be processed. Is there an easy way using python to obtain access to the clients webcam or is it possible to use JavaScript in conjunction with my current code.

Chip
  • 81
  • 1
  • 3

1 Answers1

9

I'll assume that you are more interested in architectural decisions for you application that specific implementation details. You will need to use client side and server side for this application.

Client side is html page with javascript that will capture images from web cam. There are many resources on internet about this topic. This article explains how it works with some examples. I would recommend to use some javascript library like this one

The next thing is to decide how client application and server side transfers image data. In case you would like to stream webcam video to server, do some computation and stream data back to client application, WebSockets are your friend. This tutorial describes how to set up flask application for websockets.

Much easier approach is to POST image data to the server, do some computation and respond to client. Downside of this approach is that it's not suitable for continuous video processing. But you can use it for single video frame processing. Otherwise you would flooded your server with requests.

The last thing to decide is how much processing is done to images on server side. If you would do some extensive computation that takes long time, I would recommend celery for background tasks. HOWEVER this would change architecture considerably.

For a proof of concept, I would recommend following. Take single image with webcam, post it to server, do quick computation on image and respond with what you've had computed.

Good luck.

sjudǝʊ
  • 1,565
  • 1
  • 23
  • 34
  • The information above is great it really clears some things up in how to go about the solution. I ended up figuring out the solution before the reply and I used the WebcamJS library and the Post method to send data to the server. This all works in conjunction with Flask, Python, and OpenCV. – Chip Mar 03 '16 at 15:32
  • How webrtc fits in your description? – Mostafa Jul 22 '16 at 23:58
  • 1
    The referenced webcam js library is in maintenance mode now. https://github.com/jhuckaby/webcamjs Hey everyone! WebcamJS v1.x is going into maintenance mode as of Feb 11, 2017. this SO question has a more recent solution. – CodingMatters Dec 15 '18 at 06:37