OpenCV Web

A very simple example to run Python's OpenCV in the backend and interact with the user with javascrit in the frontend.

This example steps:

  • It displays a video file loaded with opencv in the web page streaming it as a jpg sequence

  • The video stops at frame 10

  • You can make a rectangle selection at the frame (with Javascript)

  • When you click send (or refresh the page) the rectangle attributes are send to python with http GET

  • The rectangle is painted at frames by OpenCV

Run locally

Requirements

*Suggestion: Use pyenv + pipenv to manage python and libs versions

Python 3.7.9
Pipenv
OpenCV Python

Run

Install dependencies

pipenv install

Enable Virtual Enviroment

pipenv shell

Run Flask

python3 -m flask run

Run from container

Requirements

Docker

Build image

docker build -t opencvweb .

Run container

docker run -it --name opencvweb -p 5000:5000 opencvweb