0

我已经在这里问过了,但我只是想知道这是否不能用 numpy 本地完成,因为我稍后将使用 numpy 与读取 numpy 数组的 cv2 一起使用。

背景是,我从 USB 相机读取了 13 块 13680 字节,直到我得到 177840 字节,这是一个原始帧。我通过附加块来做到这一点:

frame = dev.read(0x81, 0x3570, tout)
frame += dev.read(0x81, 0x3570, tout)
...

然后用 0-255 值填充列表,其中两个值应形成一个 0-65535 值。所以我的问题是如何将(我假设)uint8 LSB 列表转换为列表一半大小的 uint16 numpy 数组。

假设我有那个列表:

list = [3,103,3,103]

然后我想要一个numpy数组:

[26371, 26371]

或者有没有办法直接用我的 USB 设备读取的 13 次填充一个 numpy 数组,以便它最后有 177840/2 uint16 值?

4

1 回答 1

1

我也许明白了。

list = [3,103,3,103]
nlist = np.asarray(list, dtype='<B')
nlist = nlist.view(np.uint16)
print nlist, type(nlist[0])

输出:

[26371 26371] <type 'numpy.uint16'>
于 2018-06-28T10:01:49.067 回答