我正在使用套接字从运行wince的相机传输图像。相机中的图像只是使用realloc创建的float数组,大小为x * y。
另一端,我在python中接收这些图像。我已经编写了代码执行此操作。
另一端,我在python中接收这些图像。我已经编写了代码执行此操作。
img_dtype = np.float32
img_rcv = np.empty((img_y, img_x),
dtype = img_dtype)
p = sck.recv_into(img_rcv,
int(size_bytes),
socket.MSG_WAITALL)
if size_bytes != p:
print "Mismatch between expected and received data amount"
return img_rcv
我对numpy创建数组的方式有些困惑,不确定这个img_rcv是否与recv_into的工作方式兼容。
我的问题是:
- 这样做是否安全?
- numpy数组的内存分配是否对recv_into知晓?
- numpy数组创建例程是否等同于malloc?
- 这只是因为我运气好吗?