首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从OpenCV创建RTSP流

从OpenCV创建RTSP流
EN

Stack Overflow用户
提问于 2021-10-05 04:07:21
回答 1查看 276关注 0票数 1

我正在处理一个输入,每帧需要不同的时间。目标是将这些以numpy数组(OpenCV处理)加载的图像作为视频处理,并将其作为RTSP流发送到Kivy视频应用程序中。

我没有成功地找到或实现任何好的解决方案。有什么想法吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-10-06 03:27:02

因此,要流式传输一个OpenCV图像,请使用imagezmq包并创建一个客户机/服务器。这可以用来接收随机时间到达的输入图像。本质上,它总是发送一个图像,并且只发送最近更新的图像。

这通过TCP进行流式传输,然后可以在应用程序中显示输出。

以下代码应用于演示目的,在同一设备上的不同内核中启动(imagezmq.ImageSender()默认为127.0.0.1)。

客户端:

代码语言:javascript
复制
import socket
import imagezmq
import threading

class Streamer():

    '''
    Create a TCP stream
    '''

    def __init__(self):

        self.sender = imagezmq.ImageSender()

        self.deviceName = socket.gethostname()

        # launch the streamer thread
        threading.Thread(target=self.sendImage, name = "ImageStreamer").start()

        # initialise the image as empty
        self.img = None

        # set to run
        self.run = True
        

    def sendImage(self):

        ''''
        Take the objects image and send it
        '''

        while self.run:
            try:
                if self.img is not None:
                    self.sender.send_image(self.deviceName, self.img)

                else:
                    time.sleep(0.1)
            except Exception as e:
                print(e)

        print("---- Stream finished ----")

stream = Streamer()
while True:

    '''
    Processing and extraction of the image at whatever interval.
    Should send a numpy array representing the image. 
    '''

    stream.img = image

服务器:

代码语言:javascript
复制
import imagezmq
import cv2

imageHub = imagezmq.ImageHub()

lastActive = {}

while True:
    # receive the device name and decoded image
    (name, frame) = imageHub.recv_image()

    # update the frame at ~50fps
    cv2.imshow("Frame", frame.astype(np.uint8))
    cv2.waitKey(20) 

    # send back confirmation message
    imageHub.send_reply(b'OK')

    if name not in lastActive.keys():
        print("[INFO] receiving data from {}...".format(rpiName))
    lastActive[name] = time.time()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69444809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档