当前位置:网站首页>[openvx] VX for basic use of objects_ image
[openvx] VX for basic use of objects_ image
2022-07-28 03:39:00 【zhy29563】
Catalog
1. Test source
#include <iostream>
#include <VX/vx.h>
vx_df_image_e df_images[]{
VX_DF_IMAGE_VIRT,
VX_DF_IMAGE_RGB,
VX_DF_IMAGE_RGBX,
VX_DF_IMAGE_NV12,
VX_DF_IMAGE_NV21,
VX_DF_IMAGE_UYVY,
VX_DF_IMAGE_YUYV,
VX_DF_IMAGE_IYUV,
VX_DF_IMAGE_YUV4,
VX_DF_IMAGE_U8,
VX_DF_IMAGE_U16,
VX_DF_IMAGE_S16,
VX_DF_IMAGE_U32,
VX_DF_IMAGE_S32,
VX_DF_IMAGE_U1};
std::string get_string_vx_df_image_e(vx_df_image_e format) {
switch (format) {
case VX_DF_IMAGE_VIRT:
return std::string("VX_DF_IMAGE_VIRT");
case VX_DF_IMAGE_RGB:
return std::string("VX_DF_IMAGE_RGB");
case VX_DF_IMAGE_RGBX:
return std::string("VX_DF_IMAGE_RGBX");
case VX_DF_IMAGE_NV12:
return std::string("VX_DF_IMAGE_NV12");
case VX_DF_IMAGE_NV21:
return std::string("VX_DF_IMAGE_NV21");
case VX_DF_IMAGE_UYVY:
return std::string("VX_DF_IMAGE_UYVY");
case VX_DF_IMAGE_YUYV:
return std::string("VX_DF_IMAGE_YUYV");
case VX_DF_IMAGE_IYUV:
return std::string("VX_DF_IMAGE_IYUV");
case VX_DF_IMAGE_U8:
return std::string("VX_DF_IMAGE_U8");
case VX_DF_IMAGE_U16:
return std::string("VX_DF_IMAGE_U16");
case VX_DF_IMAGE_S16:
return std::string("VX_DF_IMAGE_S16");
case VX_DF_IMAGE_U32:
return std::string("VX_DF_IMAGE_U32");
case VX_DF_IMAGE_S32:
return std::string("VX_DF_IMAGE_S32");
case VX_DF_IMAGE_YUV4:
return std::string("VX_DF_IMAGE_YUV4");
case VX_DF_IMAGE_U1:
return std::string("VX_DF_IMAGE_U1");
}
return std::string("");
}
std::string get_string_vx_color_space_e(vx_color_space_e color_space) {
switch (color_space) {
case VX_COLOR_SPACE_NONE:
return std::string("VX_COLOR_SPACE_NONE");
case VX_COLOR_SPACE_BT601_525:
return std::string("VX_COLOR_SPACE_BT601_525");
case VX_COLOR_SPACE_BT601_625:
return std::string("VX_COLOR_SPACE_BT601_625");
case VX_COLOR_SPACE_BT709:
return std::string("VX_COLOR_SPACE_BT709");
}
return std::string("");
}
std::string get_string_vx_channel_range_e(vx_channel_range_e channel_range) {
switch (channel_range) {
case VX_CHANNEL_RANGE_FULL:
return std::string("VX_CHANNEL_RANGE_FULL");
case VX_CHANNEL_RANGE_RESTRICTED:
return std::string("VX_CHANNEL_RANGE_RESTRICTED");
}
return std::string("");
}
std::string get_string_vx_memory_type_e(vx_memory_type_e memory_type) {
switch (memory_type) {
case VX_MEMORY_TYPE_NONE:
return std::string("VX_MEMORY_TYPE_NONE");
case VX_MEMORY_TYPE_HOST:
return std::string("VX_MEMORY_TYPE_HOST");
}
return std::string("");
}
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 : " << get_string_vx_df_image_e(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 : " << get_string_vx_color_space_e(color_space) << std::endl;
std::cout << "\t" << "channel_range : " << get_string_vx_channel_range_e(channel_range) << std::endl;
std::cout << "\t" << "memory_type : " << get_string_vx_memory_type_e(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);
}
}
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
vx_status status;
vx_context context = vxCreateContext();
// for (auto &df_image : df_images) {
// vx_image image_created = vxCreateImage(context, 400, 300, df_image);
// print_image(image_created, "created");
// vxReleaseImage(&image_created);
// }
// Create an image
vx_image image_created = vxCreateImage(context, 400, 300, VX_DF_IMAGE_S32);
print_image(image_created, "created");
// Set image properties
{
vx_color_space_e color_space = VX_COLOR_SPACE_DEFAULT;
vxSetImageAttribute(image_created, (vx_enum) VX_IMAGE_SPACE, &color_space, sizeof(color_space));
print_image(image_created, "update attributes");
}
// Set pixel values
{
vx_pixel_value_t pixel_value{
.S32=-32768};
vxSetImagePixelValues(image_created, &pixel_value);
print_image(image_created, "set pixel value");
}
// Set legal area
{
vx_rectangle_t valid_rect{
.start_x=50, .start_y=50, .end_x=250, .end_y=250};
vxSetImageValidRectangle(image_created, &valid_rect);
print_image(image_created, "set valid rect");
}
// Create images from channel data
{
vx_image image_created_from_channel = vxCreateImageFromChannel(image_created, 0);
print_image(image_created_from_channel, "image_created_from_channel");
vxReleaseImage(&image_created_from_channel);
}
// from ROI Create an image
{
vx_rectangle_t roi{
.start_x=100, .start_y=100, .end_x=200, .end_y=200};
vx_image image_created_from_roi = vxCreateImageFromROI(image_created, &roi);
print_image(image_created_from_roi, "image_created_from_roi");
vxReleaseImage(&image_created_from_roi);
}
// Create an image with a specified pixel value
{
vx_pixel_value_t pixel_value{
.S32=200};
vx_image image_created_uniform = vxCreateUniformImage(context, 400, 300, VX_DF_IMAGE_S32, &pixel_value);
print_image(image_created_uniform, "image_created_uniform");
vxReleaseImage(&image_created_uniform);
}
// Create an image based on existing data
vx_image image_created_from_handle;
vx_uint8 *pixel_data[]{
new vx_uint8[10 * 8]};
{
vx_imagepatch_addressing_t addr[]{
{
.dim_x=10, .dim_y=8, .stride_x=1, .stride_y=10}};
image_created_from_handle = vxCreateImageFromHandle(context, VX_DF_IMAGE_U8, addr, (void **) pixel_data,VX_MEMORY_TYPE_HOST);
print_image(image_created_from_handle, "image_created_from_handle");
}
// Image data address exchange
vx_uint8 *pixel_data_new[]{
new vx_uint8[10 * 8]};
{
for (int i = 0; i < 80; ++i) {
pixel_data_new[0][i] = i;
}
vxSwapImageHandle(image_created_from_handle, (void **) pixel_data_new, nullptr, 1);
print_image(image_created_from_handle, "swap image handle");
}
// Use one-dimensional address to obtain pixel value
{
std::cout << "===============================" << std::endl;
std::cout << "address 1d" << std::endl;
vx_rectangle_t patch;
vxGetValidRegionImage(image_created_from_handle, &patch);
vx_imagepatch_addressing_t addr = VX_IMAGEPATCH_ADDR_INIT;
vx_map_id map_id;
unsigned char *ptr;
vxMapImagePatch(image_created_from_handle, &patch, 0, &map_id, &addr, (void **) &ptr, VX_READ_ONLY,VX_MEMORY_TYPE_HOST, VX_NOGAP_X);
for (int row = 0; row < addr.dim_y; ++row) {
std::cout << "\t";
for (int col = 0; col < addr.dim_x; ++col) {
std::cout << (int) *((vx_uint8 *) vxFormatImagePatchAddress1d(ptr, row * addr.dim_x + col, &addr)) << "\t";
}
std::cout << std::endl;
}
vxUnmapImagePatch(image_created_from_handle, map_id);
}
// Use the two-dimensional address to obtain the pixel value
{
std::cout << "===============================" << std::endl;
std::cout << "address 2d" << std::endl;
vx_rectangle_t patch;
vxGetValidRegionImage(image_created_from_handle, &patch);
vx_imagepatch_addressing_t addr = VX_IMAGEPATCH_ADDR_INIT;
vx_map_id map_id;
unsigned char *ptr;
vxMapImagePatch(image_created_from_handle, &patch, 0, &map_id, &addr, (void **) &ptr, VX_READ_ONLY,VX_MEMORY_TYPE_HOST, VX_NOGAP_X);
for (int row = 0; row < addr.dim_y; ++row) {
std::cout << "\t";
for (int col = 0; col < addr.dim_x; ++col) {
std::cout << (int) *((vx_uint8 *) vxFormatImagePatchAddress2d(ptr, col, row, &addr)) << "\t";
}
std::cout << std::endl;
}
vxUnmapImagePatch(image_created_from_handle, map_id);
}
delete[] pixel_data_new[0];
delete[] pixel_data[0];
vxReleaseImage(&image_created);
vxReleaseImage(&image_created_from_handle);
vxReleaseContext(&context);
return EXIT_SUCCESS;
}
2. Running results
===============================
created
format : VX_DF_IMAGE_S32
img_width : 400
img_height : 300
planes : 1
color_space : VX_COLOR_SPACE_NONE
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 400
end_y : 300
image patch addressing :
plane : 0
addr.dim_x : 400
addr.dim_y : 300
addr.stride_x: 4
addr.stride_y: 1600
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
update attributes
format : VX_DF_IMAGE_S32
img_width : 400
img_height : 300
planes : 1
color_space : VX_COLOR_SPACE_BT709
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 400
end_y : 300
image patch addressing :
plane : 0
addr.dim_x : 400
addr.dim_y : 300
addr.stride_x: 4
addr.stride_y: 1600
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
set pixel value
format : VX_DF_IMAGE_S32
img_width : 400
img_height : 300
planes : 1
color_space : VX_COLOR_SPACE_BT709
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 400
end_y : 300
image patch addressing :
plane : 0
addr.dim_x : 400
addr.dim_y : 300
addr.stride_x: 4
addr.stride_y: 1600
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
set valid rect
format : VX_DF_IMAGE_S32
img_width : 400
img_height : 300
planes : 1
color_space : VX_COLOR_SPACE_BT709
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 50
start_y : 50
end_x : 250
end_y : 250
image patch addressing :
plane : 0
addr.dim_x : 200
addr.dim_y : 200
addr.stride_x: 4
addr.stride_y: 800
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
image_created_from_channel
format :
img_width : 0
img_height : 0
planes : 0
color_space :
channel_range :
memory_type :
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 0
end_y : 0
image patch addressing :
===============================
image_created_from_roi
format : VX_DF_IMAGE_S32
img_width : 100
img_height : 100
planes : 1
color_space : VX_COLOR_SPACE_BT709
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 100
end_y : 100
image patch addressing :
plane : 0
addr.dim_x : 100
addr.dim_y : 100
addr.stride_x: 4
addr.stride_y: 400
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
image_created_uniform
format : VX_DF_IMAGE_S32
img_width : 400
img_height : 300
planes : 1
color_space : VX_COLOR_SPACE_NONE
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_NONE
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 400
end_y : 300
image patch addressing :
plane : 0
addr.dim_x : 400
addr.dim_y : 300
addr.stride_x: 4
addr.stride_y: 1600
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
image_created_from_handle
format : VX_DF_IMAGE_U8
img_width : 10
img_height : 8
planes : 1
color_space : VX_COLOR_SPACE_NONE
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_HOST
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 10
end_y : 8
image patch addressing :
plane : 0
addr.dim_x : 10
addr.dim_y : 8
addr.stride_x: 1
addr.stride_y: 10
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
swap image handle
format : VX_DF_IMAGE_U8
img_width : 10
img_height : 8
planes : 1
color_space : VX_COLOR_SPACE_NONE
channel_range : VX_CHANNEL_RANGE_FULL
memory_type : VX_MEMORY_TYPE_HOST
is_uniform : 0
valid region :
start_x : 0
start_y : 0
end_x : 10
end_y : 8
image patch addressing :
plane : 0
addr.dim_x : 10
addr.dim_y : 8
addr.stride_x: 1
addr.stride_y: 10
addr.scale_x : 1024
addr.scale_y : 1024
addr.step_x : 1
addr.step_y : 1
===============================
address 1d
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
===============================
address 2d
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
边栏推荐
- CF 7月25日-7月31日做题记录
- Unity背包系统
- AI chief architect 12 AICA Baidu OCR vertical large-scale landing practice
- In December, the PMP Exam adopted the new syllabus for the first time. How to learn?
- 20220727使用汇承科技的蓝牙模块HC-05配对手机进行蓝牙串口的演示
- 什么是Tor?Tor浏览器更新有什么用?
- 【OPENVX】对象基本使用之vx_matrix
- leetcode刷题:动态规划09(最后一块石头的重量 II)
- Leetcode 29th day
- deepstream 检测结果截图
猜你喜欢

8000 word explanation of OBSA principle and application practice

Win11 how to rename an audio device

Airiot Q & A issue 6 | how to use the secondary development engine?

Collection | 0 basic open source data visualization platform flyfish large screen development guide

An article grasps the calculation and processing of date data in PostgreSQL

Shell: resource monitoring script and high load alarm

Mouse operation and response

What are the fragments of MySQL

如何让外网访问内网IP(esp8266网页使用)

What is tor? What is the use of tor browser update?
随机推荐
Asemi rectifier bridge gbpc5010, gbpc5010 parameters, gbpc5010 size
ES6 from entry to mastery 07: Deconstruction assignment
[错题]Concatenation
Version compatibility issues
容器相关的概念
Swift中的协议
STM32 RT thread virtual file system mount operation
Outlook 教程,如何在 Outlook 中使用颜色类别和提醒?
Redis基本操作
沃尔沃:深入人心的“安全感” 究竟靠的是什么?
Collection | 0 basic open source data visualization platform flyfish large screen development guide
20220727 use the Bluetooth module hc-05 of Huicheng technology to pair mobile phones for Bluetooth serial port demonstration
收藏|0 基础开源数据可视化平台 FlyFish 大屏开发指南
Shell writing specifications and variables
一篇文章掌握Postgresql中对于日期类数据的计算和处理
ES6 from getting started to mastering 09: symbol type
Unity simply implements the dialog function
Billions of asset addresses are blacklisted? How to use the tether address freezing function?
最新版宝塔安装zip扩展,php -m 不显示的处理方法
Robot development -- lead screw and guide rail