【OPENVX】对象基本使用之vx_distribution

1. 程序源码

#include <iostream>
#include <VX/vx.h>

void print_distribution(vx_distribution distribution, const char *message)
{
    std::cout << "===============================" << std::endl;
    std::cout << message << std::endl;

    vx_size dimensions;
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_DIMENSIONS, &dimensions, sizeof(dimensions));

    vx_int32 offset;
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_OFFSET, &offset, sizeof(offset));

    vx_uint32 range; // 需要为bins的倍数
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_RANGE, &range, sizeof(range));

    vx_size bins; // BIN的数量
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_BINS, &bins, sizeof(bins));

    vx_uint32 window; // BIN的宽度 window=RANGE/BINS
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_WINDOW, &window, sizeof(window));

    vx_size size; // 总字节数
    vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_SIZE, &size, sizeof(size));

    std::cout << "dimensions    : " << dimensions << std::endl;
    std::cout << "offset        : " << offset << std::endl;
    std::cout << "range         : " << range << std::endl;
    std::cout << "bins          : " << bins << std::endl;
    std::cout << "window        : " << window << std::endl;
    std::cout << "size          : " << size << std::endl;

    vx_map_id map_id;
    void* ptr;
    // 输出的地址是 vx_uint32 的数组,数量为 VX_DISTRIBUTION_BINS 的返回值
    std::cout << "item          : " << std::endl;
    vxMapDistribution(distribution, &map_id, &ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0);
    for (int i = 0; i < bins; ++i) {
        std::cout << "\t" << "index: " << i << ", value: " << ((vx_uint32*)ptr)[i] << std::endl;
    }
    vxUnmapDistribution(distribution, map_id);
}

int main(int argc, char *argv[])
{
    (void) argc;
    (void) argv;

    vx_status status;
    vx_context context = vxCreateContext();

    vx_size bins = 64;
    vx_uint32 offset = 0U;
    vx_uint32 range = 256U;
    vx_distribution distribution = vxCreateDistribution(context, bins, offset, range);
    print_distribution(distribution, "create");

    vx_uint32* array = new vx_uint32 [bins];
    for (int i = 0; i < bins; ++i) {
        array[i] = i;
    }
    vxCopyDistribution(distribution, array, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);
    print_distribution(distribution, "update");
    delete[] array;

    vxReleaseDistribution(&distribution);
    vxReleaseContext(&context);
    return EXIT_SUCCESS;
}

2. 运行结果

===============================
create
dimensions : 1
offset : 0
range : 256
bins : 64
window : 4
size : 256
item :
index: 0, value: 0
index: 1, value: 0
index: 2, value: 0
index: 3, value: 0
index: 4, value: 0
index: 5, value: 0
index: 6, value: 0
index: 7, value: 0
index: 8, value: 0
index: 9, value: 0
index: 10, value: 0
index: 11, value: 0
index: 12, value: 0
index: 13, value: 0
index: 14, value: 0
index: 15, value: 0
index: 16, value: 0
index: 17, value: 0
index: 18, value: 0
index: 19, value: 0
index: 20, value: 0
index: 21, value: 0
index: 22, value: 0
index: 23, value: 0
index: 24, value: 0
index: 25, value: 0
index: 26, value: 0
index: 27, value: 0
index: 28, value: 0
index: 29, value: 0
index: 30, value: 0
index: 31, value: 0
index: 32, value: 0
index: 33, value: 0
index: 34, value: 0
index: 35, value: 0
index: 36, value: 0
index: 37, value: 0
index: 38, value: 0
index: 39, value: 0
index: 40, value: 0
index: 41, value: 0
index: 42, value: 0
index: 43, value: 0
index: 44, value: 0
index: 45, value: 0
index: 46, value: 0
index: 47, value: 0
index: 48, value: 0
index: 49, value: 0
index: 50, value: 0
index: 51, value: 0
index: 52, value: 0
index: 53, value: 0
index: 54, value: 0
index: 55, value: 0
index: 56, value: 0
index: 57, value: 0
index: 58, value: 0
index: 59, value: 0
index: 60, value: 0
index: 61, value: 0
index: 62, value: 0
index: 63, value: 0

===============================
update
dimensions : 1
offset : 0
range : 256
bins : 64
window : 4
size : 256
item :
index: 0, value: 0
index: 1, value: 1
index: 2, value: 2
index: 3, value: 3
index: 4, value: 4
index: 5, value: 5
index: 6, value: 6
index: 7, value: 7
index: 8, value: 8
index: 9, value: 9
index: 10, value: 10
index: 11, value: 11
index: 12, value: 12
index: 13, value: 13
index: 14, value: 14
index: 15, value: 15
index: 16, value: 16
index: 17, value: 17
index: 18, value: 18
index: 19, value: 19
index: 20, value: 20
index: 21, value: 21
index: 22, value: 22
index: 23, value: 23
index: 24, value: 24
index: 25, value: 25
index: 26, value: 26
index: 27, value: 27
index: 28, value: 28
index: 29, value: 29
index: 30, value: 30
index: 31, value: 31
index: 32, value: 32
index: 33, value: 33
index: 34, value: 34
index: 35, value: 35
index: 36, value: 36
index: 37, value: 37
index: 38, value: 38
index: 39, value: 39
index: 40, value: 40
index: 41, value: 41
index: 42, value: 42
index: 43, value: 43
index: 44, value: 44
index: 45, value: 45
index: 46, value: 46
index: 47, value: 47
index: 48, value: 48
index: 49, value: 49
index: 50, value: 50
index: 51, value: 51
index: 52, value: 52
index: 53, value: 53
index: 54, value: 54
index: 55, value: 55
index: 56, value: 56
index: 57, value: 57
index: 58, value: 58
index: 59, value: 59
index: 60, value: 60
index: 61, value: 61
index: 62, value: 62
index: 63, value: 63

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
To create a `vx_image` out of an array, you can use the OpenVX API. Here's an example: ``` vx_context context = vxCreateContext(); // Define the image properties vx_uint32 width = 640; vx_uint32 height = 480; vx_df_image format = VX_DF_IMAGE_U8; // Create the image vx_image image = vxCreateImage(context, width, height, format); // Get the image properties vx_uint32 image_width, image_height; vx_df_image image_format; vxQueryImage(image, VX_IMAGE_WIDTH, &image_width, sizeof(image_width)); vxQueryImage(image, VX_IMAGE_HEIGHT, &image_height, sizeof(image_height)); vxQueryImage(image, VX_IMAGE_FORMAT, &image_format, sizeof(image_format)); // Create an array to hold the image data vx_uint8 *data = (vx_uint8*)malloc(image_width * image_height * sizeof(vx_uint8)); // Fill the array with data (e.g. from a file) // ... // Copy the array into the image vx_imagepatch_addressing_t addr; addr.dim_x = image_width; addr.dim_y = image_height; addr.scale_x = VX_SCALE_UNITY; addr.scale_y = VX_SCALE_UNITY; addr.step_x = sizeof(vx_uint8); addr.step_y = image_width * sizeof(vx_uint8); vx_imagepatch_rect_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = image_width; rect.end_y = image_height; vxCopyImagePatch(image, &rect, 0, &addr, data, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); // Use the image for processing // ... // Release resources vxReleaseImage(&image); vxReleaseContext(&context); free(data); ``` This code creates an OpenVX context, creates an image with the specified properties, creates an array to hold the image data, fills the array with data, and copies the array into the image. You can then use the image for processing and release the resources when you're done.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhy29563

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值