【OPENVX】对象基本使用之vx_pyramid

1. 测试源码

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

void print_image(vx_image image, const char *message) {
    vx_status status;

    std::cout << "===============================" << std::endl;
    std::cout << message << std::endl;

    vx_uint32 img_width;
    vxQueryImage(image, VX_IMAGE_WIDTH, &img_width, sizeof(vx_uint32));

    vx_uint32 img_height;
    vxQueryImage(image, VX_IMAGE_HEIGHT, &img_height, sizeof(vx_uint32));

    vx_df_image_e format;
    vxQueryImage(image, VX_IMAGE_FORMAT, &format, sizeof(vx_df_image));

    vx_size planes;
    vxQueryImage(image, VX_IMAGE_PLANES, &planes, sizeof(vx_size));

    vx_color_space_e color_space;
    vxQueryImage(image, VX_IMAGE_SPACE, &color_space, sizeof(vx_color_space_e));

    vx_channel_range_e channel_range;
    vxQueryImage(image, VX_IMAGE_RANGE, &channel_range, sizeof(vx_channel_range_e));

    vx_memory_type_e memory_type;
    vxQueryImage(image, VX_IMAGE_MEMORY_TYPE, &memory_type, sizeof(vx_memory_type_e));

    vx_bool is_uniform;
    vx_pixel_value_t uniform_value;
    status = vxQueryImage(image, VX_IMAGE_IS_UNIFORM, &is_uniform, sizeof(is_uniform));
    if (status != VX_SUCCESS)
        is_uniform = false, uniform_value.S32 = -32768;

    if (is_uniform == vx_true_e) {
        status = vxQueryImage(image, VX_IMAGE_UNIFORM_VALUE, &uniform_value, sizeof(uniform_value));
        if (status != VX_SUCCESS)
            uniform_value.S32 = -32768;
    }

    std::cout << "\t" << "format        : " << format << std::endl;
    std::cout << "\t" << "img_width     : " << img_width << std::endl;
    std::cout << "\t" << "img_height    : " << img_height << std::endl;
    std::cout << "\t" << "planes        : " << planes << std::endl;
    std::cout << "\t" << "color_space   : " << color_space << std::endl;
    std::cout << "\t" << "channel_range : " << channel_range << std::endl;
    std::cout << "\t" << "memory_type   : " << memory_type << std::endl;
    std::cout << "\t" << "is_uniform    : " << is_uniform << std::endl;
    if (is_uniform)
        std::cout << "\t" << "uniform_value : " << uniform_value.S32 << std::endl;

    std::cout << "\t" << "valid region  : " << std::endl;
    vx_rectangle_t patch;
    vxGetValidRegionImage(image, &patch);
    std::cout << "\t" << "\t" << "start_x   : " << patch.start_x << std::endl;
    std::cout << "\t" << "\t" << "start_y   : " << patch.start_y << std::endl;
    std::cout << "\t" << "\t" << "end_x     : " << patch.end_x << std::endl;
    std::cout << "\t" << "\t" << "end_y     : " << patch.end_y << std::endl;

    std::cout << "\t" << "image patch addressing   : " << std::endl;
    for (size_t i = 0; i < planes; i++) {
        vx_imagepatch_addressing_t addr = VX_IMAGEPATCH_ADDR_INIT;

        vx_map_id map_id;
        unsigned char *ptr;
        vxMapImagePatch(image, &patch, i, &map_id, &addr, (void **) &ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST,VX_NOGAP_X);
        std::cout << "\t" << "\t" << "plane        : " << i << std::endl;
        std::cout << "\t" << "\t" << "addr.dim_x   : " << addr.dim_x << std::endl;
        std::cout << "\t" << "\t" << "addr.dim_y   : " << addr.dim_y << std::endl;
        std::cout << "\t" << "\t" << "addr.stride_x: " << addr.stride_x << std::endl;
        std::cout << "\t" << "\t" << "addr.stride_y: " << addr.stride_y << std::endl;
        std::cout << "\t" << "\t" << "addr.scale_x : " << addr.scale_x << std::endl;
        std::cout << "\t" << "\t" << "addr.scale_y : " << addr.scale_y << std::endl;
        std::cout << "\t" << "\t" << "addr.step_x  : " << addr.step_x << std::endl;
        std::cout << "\t" << "\t" << "addr.step_y  : " << addr.step_y << std::endl;
        std::cout << std::endl;
        vxUnmapImagePatch(image, map_id);
    }
}

void print_pyramid(vx_pyramid pyramid, const char *message)
{
    std::cout << "===============================" << std::endl;
    std::cout << message << std::endl;

    vx_size level;
    vxQueryPyramid(pyramid, (vx_enum)VX_PYRAMID_LEVELS, &level, sizeof(level));

    vx_float32 scale;
    vxQueryPyramid(pyramid, (vx_enum)VX_PYRAMID_SCALE, &scale, sizeof(scale));

    vx_uint32 width;
    vxQueryPyramid(pyramid, (vx_enum)VX_PYRAMID_WIDTH, &width, sizeof(width));

    vx_uint32 height;
    vxQueryPyramid(pyramid, (vx_enum)VX_PYRAMID_HEIGHT, &height, sizeof(height));

    vx_df_image format;
    vxQueryPyramid(pyramid, (vx_enum)VX_PYRAMID_FORMAT, &format, sizeof(format));

    std::cout << "level   : " << level << std::endl;
    std::cout << "scale   : " << scale << std::endl;
    std::cout << "width   : " << width << std::endl;
    std::cout << "height  : " << height << std::endl;
    std::cout << "format  : " << format << std::endl;

    for (int i = 0; i <level; ++i) {
        vx_image image = vxGetPyramidLevel(pyramid, i);
        char msg[120]{0};
        sprintf(msg, "level: %d", i);
        print_image(image, msg);
    }
}



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

    vx_context context = vxCreateContext();

    vx_pyramid pyramid = vxCreatePyramid(context, 3, VX_SCALE_PYRAMID_HALF, 10, 10, VX_DF_IMAGE_U8);
    print_pyramid(pyramid, "create");

    vxReleasePyramid(&pyramid);
    vxReleaseContext(&context);
    return EXIT_SUCCESS;
}

2. 运行结果

===============================
create
level : 3
scale : 0.5
width : 10
height : 10
format : 942682197

===============================
level: 0
format : 942682197
img_width : 10
img_height : 10
planes : 1
color_space : 24576
channel_range : 28672
memory_type : 57344
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 10
end_y : 10
image patch addressing :
plane : 0
addr.dim_x : 10
addr.dim_y : 10
addr.stride_x: 1
addr.stride_y: 10
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1

===============================
level: 1
format : 942682197
img_width : 5
img_height : 5
planes : 1
color_space : 24576
channel_range : 28672
memory_type : 57344
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 5
end_y : 5
image patch addressing :
plane : 0
addr.dim_x : 5
addr.dim_y : 5
addr.stride_x: 1
addr.stride_y: 5
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1

===============================
level: 2
format : 942682197
img_width : 3
img_height : 3
planes : 1
color_space : 24576
channel_range : 28672
memory_type : 57344
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 3
end_y : 3
image patch addressing :
plane : 0
addr.dim_x : 3
addr.dim_y : 3
addr.stride_x: 1
addr.stride_y: 3
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1

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、付费专栏及课程。

余额充值