[英]Convert a System.Drawing.Bitmap to Windows.Graphics.Imaging.SoftwareBitmap
[英]Convert ByteArray to Image File received in Python from SoftwareBitmap frame on C# Windows.Graphic.Imaging
我需要从C#中的Windows.Media.VideoFrame
获取VideoFrame.SoftwareBitMap
,然后将此SOftwareBitmap
转换为ByteArray,然后使用TCP套接字连接使用ZeroMQ将ByteArray发送到Python(使用ZMQ)。
我从C#接收Bytearray到Python,但我无法将Python中的ByteArray转换为图像。 我在python中尝试了下面的代码 -
message = socket.recv_multipart() print('message2 received' ,message[2]) img = cv2.imdecode(message[2], -1)
message [2]是整个bytearray。
我在cv2.imdecode行收到以下错误 -
TypeError:buf不是一个numpy数组,也不是标量
请告诉我我做错了什么?
收到的ByteArray(部分)示例 -
14\x1d\xff\n\x13\x1c\xff\n\x14\x1b\xff\t\x13\x1a\xff\x06\x11\x15\xff\x08\x13\x17\xff\x07\x13\x15\xff\x0c\x15\x18\xff\x0e\x17\x1a\xff\r\x14\x17\xff\x0e\x15\x18\xff\x12\x17\x1a\xff\x10\x14\x19\xff\x12\x14\x1c\xff\x12\x15\x1d\xff\x11\x16\x1f\xff\x0e\x17!\xff\x0c\x18$\xff\x0c\x18$\xff\x0c\x18"\xff\x0c\x19!\xff\x15\x1e\'\xff\x18 \'\xff\x19\x1f$\xff\x1f%,\xff\x1f$-\xff\x1e%.\xff!*4\xff\x1c%3\xff\x1e\';\xff#+B\xff&.E\xff&.E\xff#.D\xff!,B\xff\x1f*@\xff\x1e)?\xff (?\xff\x1e\';\xff %:\xff!\':\xff#%7\xff!#5\xff""2\xff$$2\xff\x1f *\xff\x17\x1a\x1f\xff\x17\x18\x1c\xff\x13\x15\x16\xff\x0e\r\x0f\xff\x07\x07\x07\xff\x00\x00\x00\xff\x01\x03\x03\xff\x04\x03\x05\xff\x01\x00\x02\xff\x04\x00\x03\xff\x06\x00\x02\xff\r\x00\x02\xff\x11\x01\x02\xff\x17\x03\x02\xff\x1a\x05\x03\xff\x18\x05\x00\xff\x19\x06\x00\xff\x1f\x08\x00\xff$\x08\x01\xff)\n\x01\xff.\n\x02\xff0\x0c\x02\xff0\r\x03\xff-\x0b\x05\xff%\t\x02\xff\x1b\x05\x00\xff\x10\x01\x00\xff\t\x00\x00\xff\x04\x00\x00\xff\x00\x00\x01\xff\x00\x00\x01\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x01\x01\x01\xff\x01\x01\x01\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\
非常感谢,Prakhar
将其另存为二进制:
outimg = open('out.jpg', wb)
outimg.write(message[2])
outimg.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.