Search code examples
pythonopencvcomputer-visionvideo-capturedronekit-python

Accessing a Video Stream running on local HTTP host


An external camera is outputing a video stream on http://localhost:3000/index.html.

I want to make this stream available to me for opencv face detection and other algorithms.

What I have tried so far:

import cv2
import warnings
warnings.filterwarnings('ignore')    

cap = cv2.VideoCapture("http://localhost:3000/index.html")

while True:

    ret, frame = cap.read()
    cv2.imshow('video', frame)

    k = cv2.waitKey(30) & 0xff
    if k == 27:  # press 'ESC' to quit
        break

This returns the following errors:

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (116) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): http://localhost:3000/ in function 'cv::icvExtractPattern'


Traceback (most recent call last):
  File "C:/Users/void_/PycharmProjects/AIML/Computer Vision/app3.py", line 18, in <module>
    cv2.imshow('video', frame)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

I have installed FFMpeg on my system. How can I go ahead with using that video stream from the local server - http://localhost:3000/index.html ? The image below shows part of the live feed and the terminal window which is running the stream.

enter image description here


Solution

  • This problem has been figured out by me.

    I was trying to extract feed from the output which was being screened onto the web browser on localhost:3000/index.html. This is an ouput from the source. So to get the feed, I needed to access the source of the feed instead which was a UDP port.

    import cv2
    import warnings
    warnings.filterwarnings('ignore')    
    
    cap = cv2.VideoCapture("udp://@0.0.0.0:11111")
    
    while True:
    
        ret, frame = cap.read()
        cv2.imshow('video', frame)
    
        k = cv2.waitKey(30) & 0xff
        if k == 27:  # press 'ESC' to quit
            break
    

    And the stream started!