C的byte数组在python中的处理

  C向Python传递数组的代码,参考《C向Python正确传递数组的代码》。

  到了python中:

  转成图片:参考《把c的char数组转换为python image的代码

  转成numpy数组:

def from_c(rgbbuffer, width, height):
    # image = Image.frombuffer('RGB', (width, height), rgbbuffer, 'raw', 'RGB', 0, 1)
    barray = np.frombuffer(rgbbuffer, dtype=np.ubyte)
    barray = barray.reshape(height, width, 3)

  上述代码中,收到一个rgb字节数组(width*height*3),将之转换为array。

猜你喜欢

转载自blog.csdn.net/quantum7/article/details/86479642
今日推荐