zoukankan      html  css  js  c++  java
  • numpy中,从一片c_void_p指向的区域里获取数据

    以前采用的数据拷贝的笨办法:

    1 bitmap_size = (1080, 1920, 3)
    2 buf = create_string_buffer(bitmap_size[0]*bitmap_size[1]*bitmap_size[2])
    3 pointer_data = c_void_p(addressof(xxxx))
    4 memmove(buf, pointer_data, bitmap_size[0]*bitmap_size[1]*bitmap_size[2])
    5 #
    6 np_arr = np.frombuffer(buf, dtype=np.uint8, count=bitmap_size[0]*bitmap_size[1]*bitmap_size[2])
    7 np_arr = np_arr.reshape(bitmap_size)

    现在找到了更好的办法,不用拷贝数据:

    1 bitmap_size = (1080, 1920, 3)
    2 bytes_count = bitmap_size[0]*bitmap_size[1]*bitmap_size[2]
    3 pointer_data = c_void_p(addressof(xxxx))
    4 #定义一个指向数组的指针
    5 array_pointer = cast(pointer_data, POINTER(c_char*bytes_count)))
    6 np_arr = np.frombuffer(array_pointer.contents, dtype=np.uint8, count=bytes_count)
    7 np_arr = np_arr.reshape(bitmap_size)
  • 相关阅读:
    CSS3选择器
    在sublimen中整理CSS代码及其兼容性问题
    sublime 插件安装
    sublime 使用快捷键
    HTML5标签选择,图文混排使用dl dt dd
    HTML布局
    分页器
    Django ==> Form 组件
    Django ==> ModelAdmin
    前端 ==> Ajax
  • 原文地址:https://www.cnblogs.com/ahfuzhang/p/10920095.html
Copyright © 2011-2022 走看看