如何对静态图片(视频)流进行动态编码,以便将这些图片从 C# 发送到 Python?

How to perform an On-the-Fly encoding of a stream of still-pictures (video) for sending these from C# to Python?

我使用 Kinect SDK ( C# ) 从 Kinect 2 获取深度和颜色帧,然后使用 将它们发送给 Python 客户端ZeroMQ.

this.shorts     = new ushort[ 217088]; //  512 *  424
this.depthBytes = new   Byte[ 434176]; //  512 *  424 * 2
this.colorBytes = new   Byte[4147200]; // 1920 * 1080 * 4

public void SendDepthFrame(DepthFrame depthFrame)
    {
        depthFrame.CopyFrameDataToArray(this.shorts);
        Buffer.BlockCopy(shorts, 0, this.depthBytes, 0, this.depthBytes.Length);
        this.depthPublisher.SendByteArray(this.depthBytes);
    }

public void SendColorFrame(ColorFrame colorFrame, WriteableBitmap map)
    {
        colorFrame.CopyRawFrameDataToArray(this.colorBytes);
        this.colorPublisher.SendByteArray(this.colorBytes);
    }

由于我要发送未压缩的数据,我正在使网络超载,我想压缩这些帧。

连续流处理是否可行?

我知道我可以通过压缩成 PNG/JPEG 格式来做到这一点,但我想保留视频流的概念。

目标是在C#中发送压缩数据,然后在Python中解码。

是否有任何库允许这样做?

可能会暂时忘记压缩,而 PoC

如果您的设计确实有意义,请尝试首先关注核心 CV-功能,但代价是降低(缩小)FPS、色深、分辨率(按此优先顺序)。

您指定的数据产生大约 1 Gbps 的出口数据流,即将到来的 CV- 处理无论如何都会阻塞,具有显着的 CV- 处理性能(延迟/延迟)/临时数据表示的内存管理瓶颈。

这就是说,PoC 可能受益于 1/4 - 1/10 慢的 FPS acquisition/stream-processing 并且微调的解决方案可能会告诉你,多少纳秒/ frame 你的代码是否有流处理余量(最终决定 iftime & processing-power 足以包含任何类型的 CODEC-处理到其他工作管道中)

check the lower-left window delays in [usec] by a right-click -> [Open in a New Tab]
to see enlarged and realise a scale / order of magnitude of a few actual openCV procesing latencies of about a 1/4 of your one FullFD still image in a real-world processing with much smaller FPS on a single-threaded i7/3.33 GHz device, where L3 cache sizes can carry as much as 15 MB of imagery-data with fastest latencies of less than 13 ns ( core-local access case ) .. 40 ns ( core-remote NUMA access case ) + block-nature of the CV-orchestrated image-processing benefits a lot from minimal if not zero cache-miss-rate -- but this is not a universal deployment hardware scenario to rely on:

没有工作流水线,没有关于持续流处理的定量数据/它是决定CODEC-困境的每帧裕度a-提议的PoC-实施的先验。