我正在处理一个输入,每帧需要不同的时间。目标是将这些以numpy数组(OpenCV处理)加载的图像作为视频处理,并将其作为RTSP流发送到Kivy视频应用程序中。
我没有成功地找到或实现任何好的解决方案。有什么想法吗?
提前谢谢。
发布于 2021-10-06 03:27:02
因此,要流式传输一个OpenCV图像,请使用imagezmq包并创建一个客户机/服务器。这可以用来接收随机时间到达的输入图像。本质上,它总是发送一个图像,并且只发送最近更新的图像。
这通过TCP进行流式传输,然后可以在应用程序中显示输出。
以下代码应用于演示目的,在同一设备上的不同内核中启动(imagezmq.ImageSender()默认为127.0.0.1)。
客户端:
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服务器:
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()https://stackoverflow.com/questions/69444809
复制相似问题