简体   繁体   中英

Using OpenCV to capture images from the Websocket stream

I have the following setup:

  1. A node server that is receiving a video stream from a client. The clients can view the video stream through a WebSocket at ws://1.2.3.4:8888.

  2. Now, I would like to use OpenCV (Python) in order to capture frames from that stream. I tried using cap = cv2.VideoCapture('ws://1.2.3.4:8888/') and it does not work. Gives me an error (note: the socket works; I tried displaying the stream on a canvas).

My question is, is there any way for me to read (in Python) frame-by-frame the stream that is available through WebSocket? Preferably using OpenCV Python?

I have tried many things, but none work.

Below is the code which gets me connected to the stream but how can I capture an image from that stream.

Thank you for your help in advance!

import asyncio
import pathlib
import ssl
import websockets

# ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
# # localhost_pem = pathlib.Path(__file__).with_name("localhost.pem")
# ssl_context.load_verify_locations(localhost_pem)

async def hello():
    uri = "ws://192.168.0.102:8080"
    async with websockets.connect(uri) as websocket:
        print('hello')

asyncio.get_event_loop().run_until_complete(hello())

You might find useful my minimalistic example of serving a live webcam feed using Python:

https://github.com/vmlaker/hello-websocket

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM