以从C传递过来的RGB byte数组为例,说明转换的办法:
def python_call_from_c(rgbbuffer, frame_width, frame_height):
# image = Image.frombuffer('RGB', (width, height), rgbbuffer, 'raw', 'RGB', 0, 1)
image = np.frombuffer(rgbbuffer, dtype=np.ubyte)
image = image.reshape(frame_height, frame_width, 3)
# RGB to BGR,已测试验证
image = image[..., ::-1]
# BGR to RGB,同上
# image = image[..., ::-1]
# RGB to GBR,未测试
# gbr = rgb[...,[2,0,1]]