当前位置:网站首页>【OPENVX】对象基本使用之vx_matrix
【OPENVX】对象基本使用之vx_matrix
2022-07-28 03:25:00 【zhy29563】
1. 测试源码
#include <iostream>
#include <VX/vx.h>
const char* get_pattern_string(vx_pattern_e pattern)
{
switch (pattern) {
case VX_PATTERN_BOX:return "VX_PATTERN_BOX";
case VX_PATTERN_CROSS:return "VX_PATTERN_CROSS";
case VX_PATTERN_DISK:return "VX_PATTERN_DISK";
case VX_PATTERN_OTHER:return "VX_PATTERN_OTHER";
}
}
void print_matrix(vx_matrix matrix, const char *message)
{
std::cout << "===============================" << std::endl;
std::cout << message << std::endl;
vx_enum type;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_TYPE, &type, sizeof(type));
vx_size rows;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_ROWS, &rows, sizeof(rows));
vx_size cols;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_COLUMNS, &cols, sizeof(cols));
vx_size size;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_SIZE, &size, sizeof(size));
vx_coordinates2d_t origin;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_ORIGIN, &origin, sizeof(origin));
vx_enum pattern;
vxQueryMatrix(matrix, (vx_enum)VX_MATRIX_PATTERN, &pattern, sizeof(pattern));
std::cout << "type : " << type << std::endl;
std::cout << "rows : " << rows << std::endl;
std::cout << "cols : " << cols << std::endl;
std::cout << "size : " << size << std::endl;
std::cout << "origin x : " << origin.x << std::endl;
std::cout << "origin y : " << origin.y << std::endl;
std::cout << "pattern : " << get_pattern_string((vx_pattern_e)pattern) << std::endl;
std::cout << "item : " << std::endl;
void* ptr = malloc(size);
vxCopyMatrix(matrix, ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST);
for (int row = 0; row < rows; ++row) {
std::cout << "\t";
for (int col = 0; col <cols; ++col) {
std::cout << (int)((vx_uint8*)ptr)[row * cols + col] << "\t";
}
std::cout << std::endl;
}
free(ptr);
}
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
vx_context context = vxCreateContext();
vx_size rows = 4;
vx_size cols = 5;
vx_matrix matrix = vxCreateMatrix(context, VX_TYPE_UINT8, cols, rows);
print_matrix(matrix, "create");
vx_uint8 *array = new vx_uint8 [rows * cols];
for (int i = 0; i < rows * cols; ++i)
array[i] = i;
vxCopyMatrix(matrix, array, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);
print_matrix(matrix, "update");
delete[] array;
vxReleaseMatrix(&matrix);
vx_matrix matrix_pattern = vxCreateMatrixFromPattern(context, VX_PATTERN_BOX, cols, rows);
print_matrix(matrix_pattern, "matrix_pattern");
vxReleaseMatrix(&matrix_pattern);
vx_matrix matrix_pattern_origin = vxCreateMatrixFromPatternAndOrigin(context, VX_PATTERN_BOX, cols, rows, 3, 3);
print_matrix(matrix_pattern_origin, "matrix_pattern_origin");
vxReleaseMatrix(&matrix_pattern_origin);
vxReleaseContext(&context);
return EXIT_SUCCESS;
}
2. 运行结果
===============================
create
type : 3
rows : 4
cols : 5
size : 20
origin x : 2
origin y : 2
pattern : VX_PATTERN_OTHER
item :
144 151 194 174 135
85 0 0 0 0
0 0 0 0 0
0 108 101 0 0
===============================
update
type : 3
rows : 4
cols : 5
size : 20
origin x : 2
origin y : 2
pattern : VX_PATTERN_OTHER
item :
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
===============================
matrix_pattern
type : 3
rows : 4
cols : 5
size : 20
origin x : 2
origin y : 2
pattern : VX_PATTERN_BOX
item :
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
===============================
matrix_pattern_origin
type : 3
rows : 4
cols : 5
size : 20
origin x : 3
origin y : 3
pattern : VX_PATTERN_BOX
item :
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
边栏推荐
- 沃尔沃:深入人心的“安全感” 究竟靠的是什么?
- 【P4】 查看库文件两个历史版本的区别
- Daily practice ----- realize the lottery function of two-color ball. Rules: Six non repeating numbers are randomly selected from 36 red balls, and one from 15 basketball is randomly selected to form a
- Mouse operation and response
- 【论文笔记】基于深度学习的移动机器人自主导航实验平台
- Play WolframAlpha computing knowledge engine
- Leetcode 208. implement trie (prefix tree) (2022.07.27)
- 动态规划——1049. 最后一块石头的重量 II
- 关于湖北文理学院平衡信标组的疑问回应
- 贪心——55. 跳跃游戏
猜你喜欢

Unity背包系统

Defect detection of BP SVM system design of leaf defect detection

Illustrated: detailed explanation of JVM memory layout

4天Excel实战训练营,0.01元特惠仅三天,赠200套学习资料包

Acid characteristics of MySQL transactions and example analysis of concurrency problems

过亿资产地址被拉入黑名单?Tether地址冻结功能该怎么用?

动态规划——62. 不同路径

Redis persistence mechanism

Redis basic operation

How to make the Internet access the intranet IP (used by esp8266 web pages)
随机推荐
贪心——55. 跳跃游戏
Daily practice ----- realize the lottery function of two-color ball. Rules: Six non repeating numbers are randomly selected from 36 red balls, and one from 15 basketball is randomly selected to form a
Malloc, free, calloc, realloc dynamic memory development functions in dynamic memory management
【OPENVX】对象基本使用之vx_lut
Summary of concurrent programming interview questions
xctf攻防世界 Web高手进阶区 PHP2
203. Remove linked list elements
How to reinstall win11 system with one click
TypeError: ufunc ‘bitwise_and‘ not supported for the input types, and the inputs could not be safely
deepstream 检测结果截图
IronOCR for .NET 2022.8
如何让外网访问内网IP(esp8266网页使用)
8000字讲透OBSA原理与应用实践
Redis基本操作
动画(animation)
响应式高端网站模板源码图库素材资源下载平台源码
Redis persistence mechanism
Robot development -- lead screw and guide rail
Methods of SQL server backup database
如何卸载干净zabbix服务?(超详细)