如何对来自WebSocket网址的视频流进行对象检测 [英] How to do object detection on a video stream coming from a websocket url

查看:51
本文介绍了如何对来自WebSocket网址的视频流进行对象检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我制作的源中获取一个流,以便可以在特定的websocket URL上访问它(不确定是否理想,也将欣赏任何其他体系结构).现在,我需要在此视频流上执行对象检测,并考虑到将通过客户端websocket库(例如通过flask或fastapi制成的服务器中的websocket)连接到websocket URL的体系结构,然后再次流传输检测到的对象通过另一个Websocket URL将视频发送给多个客户端.

I am getting a stream from a source which I made so that it can be accessed at a particular websocket URL (Not sure if this ideal and would appreciate any other architectures as well). I need to now do object detection on this video stream, and thought of the architecture that I will connect to the websocket URL through a client websocket library like websocket in a server which is made through flask or fastapi, and then again stream the object detected video to multiple clients through another websocket URL.

问题是,即使连接到websocket URL,我也无法接收任何图像,并且不确定如何在服务器方案中处理run_until_complete行.

The problem is I am unable to receive any images even after connecting to the websocket URL and am not sure how to handle asyncio in a server scenario as in where to put the line run_until_complete.

任何建议或帮助将不胜感激

Any suggestions or help would be greatly appreciated

服务器代码

import uvicorn
from fastapi import FastAPI, WebSocket
# import websockets
# import asyncio


# init app
app = FastAPI()


async def clientwebsocketconnection():
    uri = "wss://<websocket URL here>"  
    async with websockets.connect(uri) as websocket:
        print("reached here")
        data = await websocket.recv()
        print(f"< {data}")


# Routes
@app.get('/')
async def index():

    return {"text": "Its working"}


@app.websocket('/websocketconnection')  # FIXME: change this to a websocket endpoint
async def websocketconnection():

    return {"text": "Its working"}


if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8000)
    # asyncio.get_event_loop().run_until_complete(clientwebsocketconnection())

推荐答案

我假设您想通过websocket发送文本.为此,您需要以下代码:

I assume you want to send a text via websocket. TO do this you need the following code:

@app.websocket('/websocketconnection')
async def websocketconnection(websocket: WebSocket) -> None:
    await websocket.accept()
    await websocket.send_text("It's working!")
    await websocket.close()

您可能会在 FastAPI官方文档中找到更多示例.

You may find more examples in the official FastAPI docs.

这篇关于如何对来自WebSocket网址的视频流进行对象检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆