Search code examples
openvx

OpenVX Histogram


I am trying to use OpenVX Histogram (as per Spec 1.1) and little puzzled in the usage part. My understanding is like this (Please correct me):

vx_size numBins = 10;
vx_uint32 offset = 10;
vx_uint32 range = 256;
// Create Object
vx_distribution vx_dist = vxCreateDistribution (Context, numBins, offset, 
range);

// Create Node
vx_status status = vxHistogramNode (context, img, vx_dist);

Spec says that vxHistogramNode() takes vx_distribution as [out], does that means vxHistogramNode() creates object internally? If the answer is 'Yes' than how would i pass numBins, Offset and range of my choice?

Also. how can i access the output of histogram result?


Solution

  • The out means that the node will write the result to provided data object. So you pass your object to the node, run the graph and then read the result:

    // Create Object
    vx_size numBins = 10;
    vx_uint32 offset = 10;
    vx_uint32 range = 256;
    vx_distribution vx_dist = vxCreateDistribution (Context, numBins, offset, range);
    
    vx_graph graph = vxCreateGraph(context);
    vxHistogramNode(graph, img, vx_dist);
    vxVerifyGraph(graph);
    
    vxProcessGraph(graph);
    
    // Read the data
    vx_map_id map_id;
    vx_int32 *ptr;
    vxMapDistribution(vx_dist, &map_id, (void **)&ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0);
    // use ptr, like ptr[0]
    vxUnmapDistribution(vx_dist, map_id);