4

I am trying to create a web-app and I need to get video input from the webcam into Javascript or HTML and pass it to Python (Django) where I can use OpenCV with each frame.

Madhav Malik
  • 68
  • 1
  • 7

2 Answers2

2

You can use the WebRTC APIs to capture or stream video from the camera. You can check this documentation on it https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API.

And also this WebRTC implementation for Python https://github.com/aiortc/aiortc

I hope the links are of use.

fabrv
  • 384
  • 1
  • 4
  • 15
1

To access the camera in your Django template, you'll need to use JavaScript along with HTML to capture the camera feed. Here's how I did it:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
    crossorigin="anonymous">
    
<div class="container">
        <div class="row justify-content-center">
            <div class="col">
                <div class="card">
                    <div class="card-body">
                        <video id="camerafeed" autoplay controls=""></video>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        navigator.mediaDevices.getUserMedia({ video: true })
            .then(function (stream) {
                document.getElementById('camerafeed').srcObject = stream;
            })
            .catch(function (error) {
                console.log('Camera access error:', error);
            });
    </script>