openvx 4: 数据结构

Posted cheapter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openvx 4: 数据结构相关的知识,希望对你有一定的参考价值。

这篇主要整理了常见的几个对象,官方文档说明更详细,建议直接去看原文;

1 Object

openvx中的基本对象,所有对象都可以从vx_reference派生,能够在同一个context中使用;

1.1 vx_reference

引用对象,openvx中的所有对象都可以安全的转回reference类型;

每个reference对应的有一个枚举,可以获得引用计数、引用的类型及名字:

enum vx_reference_attribute_e 
    VX_REFERENCE_COUNT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REFERENCE) + 0x0,
    VX_REFERENCE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REFERENCE) + 0x1,
    VX_REFERENCE_NAME = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REFERENCE) + 0x2,
;

和reference关联的函数有:

vx_status vxGetStatus( vx_reference reference)判断是否有效
vx_context vxGetContext( vx_reference reference)获得ref的context
vx_status vxQueryReference(vx_reference ref,
                                                vx_enum attribute,
                                                void* ptr,
                                                vx_size size);

查询ref的属性

attribute:要查的属性

ptr:结果存放的位置

size: ptr所表示结果的大小

vx_status vxReleaseReference(vx_reference* ref_ptr);release ref
vx_status vxRetainReference(vx_reference ref);增加ref的引用计数

vx_status vxSetReferenceName(vx_reference ref,

                                                      const vx_char* name);

设置ref的name

1.2 Context

context是所有openvx对象的对象域。所有数据对象以及所有的框架对象都存在与上下文中。openvx context中保持对所有对象的引用计数,在析构的时候要释放对应的引用;openvx中的数据对象都是私有的,只能在同一个context中被访问;

和context相关的枚举有:

  • vx_accessor_e:内存访问模式,用于框架本身使用,用作系统关于缓存操作或编组操作中的提示;

    enum vx_accessor_e 
        VX_READ_ONLY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x1,
        VX_WRITE_ONLY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x2,
        VX_READ_AND_WRITE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x3,
    ;
  • vx_context_attribute_e:

    enum vx_context_attribute_e 
        //供应商的ID
        VX_CONTEXT_VENDOR_ID = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x0,
        
        //Openvx的版本号
        VX_CONTEXT_VERSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x1,
        
        //唯一内核的数量
        VX_CONTEXT_UNIQUE_KERNELS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x2,
        
        //注册过的模块数量
        VX_CONTEXT_MODULES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x3,
        
        //注册过的reference的数量
        VX_CONTEXT_REFERENCES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x4,
        
        //实现的名称
        VX_CONTEXT_IMPLEMENTATION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x5,
        
        //查询扩展中字符串的长度
        VX_CONTEXT_EXTENSIONS_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x6,
        
        //拓展中的字符串
        VX_CONTEXT_EXTENSIONS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x7,
        
        //卷积的最大宽度和高度
        VX_CONTEXT_CONVOLUTION_MAX_DIMENSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS,           VX_TYPE_CONTEXT) + 0x8,
    
        //金字塔核的最大尺寸
        VX_CONTEXT_OPTICAL_FLOW_MAX_WINDOW_DIMENSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x9,
    
        //立即模式
        VX_CONTEXT_IMMEDIATE_BORDER = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xA,
    
        //存放所有kernel的表
        VX_CONTEXT_UNIQUE_KERNEL_TABLE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xB,
    
        //不受支持的运行策略
        VX_CONTEXT_IMMEDIATE_BORDER_POLICY = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xC,
    
        //非线性滤波器的最大维度
        VX_CONTEXT_NONLINEAR_MAX_DIMENSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xd,
    
        //tensor的最大维度
        VX_CONTEXT_MAX_TENSOR_DIMS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xE,
    ;
  • vx_memory_type_e:内存导入的类型

enum vx_memory_type_e 
    //opencv 自己分的内存
    VX_MEMORY_TYPE_NONE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_MEMORY_TYPE) + 0x0,
    
    //主机分配的内存(系统malloc)
    VX_MEMORY_TYPE_HOST = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_MEMORY_TYPE) + 0x1,
;

  • vx_termination_criteria_e: 终止条件
enum vx_termination_criteria_e 
    //在设定的迭代次数之后终止
    VX_TERM_CRITERIA_ITERATIONS = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x0,
    
    //与提供给函数的eplison值匹配后终止
    VX_TERM_CRITERIA_EPSILON = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x1,
    
    //同时采用1 2 两种方法
    VX_TERM_CRITERIA_BOTH = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x2,
;

和context相关的函数:

vx_context vxCreateContext(void);创建
vx_status vxQueryContext(
                                        vx_context context,
                                        vx_enum attribute,
                                        void* ptr,
                                         vx_size size);
查询属性,可以查询内容见attribute枚举
vx_status vxReleaseContext(vx_context* context);release
vx_status vxSetContextAttribute(
                                                    vx_context context,
                                                    vx_enum attribute,
                                                    const void* ptr,
                                                    vx_size size);
设置属性,见attribute中可配置的属性
vx_status vxSetImmediateModeTarget(
                                                vx_context context,
                                                vx_enum target_enum,
                                                const char* target_string);
设置立即运行模式的target,对于此context的后续运行将在其target

1.3 Graph

图是以有向无环的方式连接的一组节点,下图显示了graph状态转换图:

涉及的枚举:

  • vx_graph_attributes:
    • enum vx_graph_attribute_e 
          //图中的节点数
          VX_GRAPH_NUMNODES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x0,
          
          //graph的整体性能
          VX_GRAPH_PERFORMANCE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x2,
          
          //图参数的个数
          VX_GRAPH_NUMPARAMETERS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x3,
          
          //图的状态
          VX_GRAPH_STATE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x4,
      ;
      
      //图状态
      enum vx_graph_state_e 
          VX_GRAPH_STATE_UNVERIFIED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_GRAPH_STATE) + 0x0,
          VX_GRAPH_STATE_VERIFIED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_GRAPH_STATE) + 0x1,
          VX_GRAPH_STATE_RUNNING = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_GRAPH_STATE) + 0x2,
          VX_GRAPH_STATE_ABANDONED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_GRAPH_STATE) + 0x3,
          VX_GRAPH_STATE_COMPLETED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_GRAPH_STATE) + 0x4,
      ;

        

相关函数:

vx_graph vxCreateGraph(vx_context context);创建
vx_bool vxIsGraphVerified(vx_graph graph);验证
vx_status vxProcessGraph(vx_graph graph);处理,同步接口;若graph未验证,验证后执行;阻塞至完成返回
vx_status vxQueryGraph(vx_graph graph,
                                        vx_enum attribute,
                                        void* ptr,
                                        vx_size size);
查询图的属性,可查询状态见stat_e
vx_status vxRegisterAutoAging(vx_graph graph, vx_delay delay);注册aging, 作用暂时未理解
vx_status vxReleaseGraph(vx_graph* graph);析构
vx_status vxScheduleGraph(vx_graph graph);调度,执行图(适用于auto模式)
vx_status vxSetGraphAttribute(
                                vx_graph graph,
                                vx_enum attribute,
                                const void* ptr,
                                vx_size size);
设置属性,可配置见stat_e
vx_status vxVerifyGraph(vx_graph graph);图验证
vx_status vxWaitGraph(vx_graph graph);等待特定图执行完成

1.4 node

节点是内核的一个实例,其与一组特定的reference参数配对;结点仅在单个图中创建并在此图内可见;

属性枚举:

enum vx_node_attribute_e 
    //节点执行状态
    VX_NODE_STATUS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x0,
    
    //节点执行性能,需要启用性能跟踪
    VX_NODE_PERFORMANCE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x1,
    
    //节点的边界模式
    VX_NODE_BORDER = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x2,
    
    //kernel的内存占用
    VX_NODE_LOCAL_DATA_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x3,
    
    //本地内存的地址
    VX_NODE_LOCAL_DATA_PTR = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x4,
    
    //节点参数的个数
    VX_NODE_PARAMETERS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x5,
    
    //节点是否被复制
    VX_NODE_IS_REPLICATED = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x6,
    
    //复制的参数
    VX_NODE_REPLICATE_FLAGS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x7,
    
    //是否存在有效框
    VX_NODE_VALID_RECT_RESET = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x8,
;

相关函数:

vx_status vxQueryNode(
                        vx_node node,
                        vx_enum attribute,
                        void* ptr,
                        vx_size size);
查询属性
vx_status vxReleaseNode(vx_node* node);析构
vx_status vxRemoveNode(vx_node* node);从图中移出节点
vx_status vxReplicateNode(
                        vx_graph graph,
                        vx_node first_node,
                        vx_bool replicate[],
                        vx_uint32 number_of_parameters);
创建一个节点的复制,如处理pyramid时可以用到;复制的节点不可访问,析构基节点之后会删除所有拷贝节点
vx_status vxSetNodeAttribute(
                        vx_node node,
                        vx_enum attribute,
                        const void* ptr,
                        vx_size size);
设置属性
vx_status vxSetNodeTarget(
                        vx_node node,
                        vx_enum target_enum,
                        const char* target_string);
设置node运行的target

1.5 Others

其他类型的对象包括: Object: ArrayObject: Convolution, Object: Distribution Object: Image Object: LUTObject: MatrixObject: PyramidObject: RemapObject: ScalarObject: ThresholdObject: ObjectArrayObject: Tensor

基本用法都类似,可以查询及设置属性,更多内容可以在使用过程中查询;

 2 基本feature

主要包括这几个部分:

Modules (模块)

Data Structures (数据结构)

  • vx_coordinates2d_t: 二维坐标

  • typedef struct _vx_coordinates2d_t 
        vx_uint32    x;
        vx_uint32    y;
     vx_coordinates2d_t;
  • vx_coordinates3d_t:3d坐标

    typedef struct _vx_coordinates3d_t 
        vx_uint32    x;
        vx_uint32    y;
        vx_uint32    z;
     vx_coordinates3d_t;
     
  • vx_keypoint_t

    typedef struct _vx_keypoint_t 
        vx_int32      x;
        vx_int32      y;
        vx_float32    strength;    //The strength of the keypoint. 
        vx_float32    scale;        
        vx_float32    orientation;  
        vx_int32      tracking_status;    //A zero indicates a lost point. 
        vx_float32    error;    //A tracking method specific error.
     vx_keypoint_t;
     
  • vx_line2d_t

     
    typedef struct _vx_line2d_t 
        vx_float32    start_x;
        vx_float32    start_y;
        vx_float32    end_x;
        vx_float32    end_y;
     vx_line2d_t;

  • vx_rectangle_t

    typedef struct _vx_rectangle_t 
        vx_uint32    start_x;
        vx_uint32    start_y;
        vx_uint32    end_x;
        vx_uint32    end_y;
     vx_rectangle_t;

Macros (宏)

类型定义

Enumerations

  • vx_bool_e

  • vx_channel_e

  • vx_convert_policy_e

  • vx_df_image_e

  • vx_enum_e

  • vx_interpolation_type_e图像重采样操作支持的图像重建滤波器。

    enum vx_interpolation_type_e 
        VX_INTERPOLATION_NEAREST_NEIGHBOR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x0,
        VX_INTERPOLATION_BILINEAR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x1,
        VX_INTERPOLATION_AREA = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x2,
    ;
  • vx_non_linear_filter_e非线性滤波器函数的枚举。

  • vx_pattern_e矩阵模式的枚举

  • vx_status_e

  • vx_target_e目标枚举

    enum vx_target_e 
        VX_TARGET_ANY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TARGET) + 0x0000,
        VX_TARGET_STRING = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TARGET) + 0x0001,
        VX_TARGET_VENDOR_BEGIN = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TARGET) + 0x1000,
    ;
  • vx_type_e

  • vx_vendor_id_e

3 总结

其实这里主要理解context、graph、node、kernel之间的关系即可;包含关系node∈graph∈context;

注:边界模式是指图像使用的像素在不在图像边界之内;像素在图像边界之外使用的是VX_BORDER_UNDEFINED 模式;

以上是关于openvx 4: 数据结构的主要内容,如果未能解决你的问题,请参考以下文章

Visionworks OpenVX

VSCode自定义代码片段4——cli的终端命令大全

web代码片段

无标题

Xcode 4.6 的备份代码片段

4.3 合并重复的条件执行片段