自定义应用程序中的DeepStream python应用程序

问题描述

在此link中,我们想访问gstreamer管道缓冲区并转换为numpy数组中的帧缓冲区,我想知道,如何访问GPU mem中的帧缓冲区,然后将其馈送到我的自定义处理器中无需将帧转换为numpy数组。

对于深度流解码器的使用,我们有两种解决方案(比opencv + gstreamer更有效的方法): 一种方法是,我们需要编写处理的自定义元素并在gstreamer中注册,然后将自定义元素放入管道中,然后对帧缓冲区进行处理。这种方式很好,但是需要编写和了解gstreamer编程。这种方式与深流相同。 第二种方法是我们仅使用来自link的帧的解码,然后将帧传递到自定义处理器单元。对于这一部分,我有两个问题:

1- gstreamer的循环与asyncio编程的循环相同吗?

2-如您所知,如果我们在pad prob函数中添加了其他操作,则会导致性能下降,但我想知道,是否可以将帧放入pad prob函数中,并且 loop.create_task(process(frame))像异步吗?这导致我们在这里不必等待执行处理。像这样:

def tiler_sink_pad_buffer_probe(pad,info,u_data):
    ....
    ### capture the frames in GPU buffer without converting into numpy
    loop.create_task(process(frame))
    ....
    return Gst.PadProbeReturn.OK

解决方法

  1. Python 中的 Yeap gstreamer 循环是 asyncio

  2. 好吧,你可以像我一样这样做(创建全局变量的坏方法)

     ws = None
     loopIO = None
    
     def tiler_sink_pad_buffer_probe(pad,info,u_data):
         global ws
         global loopIO
         ....
         ### capture the frames in GPU buffer converting into numpy
    
         if ws and loopIO:
             _,jpeg_frame = cv2.imencode('.jpg',frame_image)
             str_pic = jpeg_frame.tobytes()
             asyncio.run_coroutine_threadsafe(ws.send(str_pic),loopIO)
         ....
         return Gst.PadProbeReturn.OK
    
     if __name__ == '__main__':
         start_server = websockets.serve(consumer_handler,'localhost',8765)
         loopIO = asyncio.get_event_loop()
         loopIO.run_until_complete(start_server)
         wst = threading.Thread(target=asyncio.get_event_loop().run_forever)
         wst.daemon = True
         wst.start()
         sys.exit(main(sys.argv))
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...