当前位置:网站首页>【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
边栏推荐
- How to uninstall clean ZABBIX service? (super detailed)
- After reading MySQL database advanced practice (SQL xiaoxuzhu)
- 某宝模拟登录,减少二次验证的方法
- 容器相关的概念
- 动态内存管理中的malloc、free、calloc、realloc动态内存开辟函数
- 同时导出多个excel,并且一个excel中包含多个sheet
- 695. Maximum area of the island
- Redis基本操作
- Robot development -- lead screw and guide rail
- ES6 从入门到精通 # 09:Symbol 类型
猜你喜欢

20220726 at command test of Bluetooth module hc-05 of Huicheng Technology

Outlook 教程,如何在 Outlook 中使用颜色类别和提醒?

Mouse operation and response

Shell:资源监控脚本和高负载报警

C语言实现动态版本的通讯录

12月份PMP考试首次采用新考纲,该怎么学?

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

How does win11 display fixed applications?

MySQL事务的ACID特性及并发问题实例分析

Shell编写规范和变量
随机推荐
Swift中的协议
xctf攻防世界 Web高手进阶区 unserialize3
Tensorboard usage record
pip-script.py‘ is not present Verifying transaction: failed
图文并茂:JVM 内存布局详解
最新版宝塔安装zip扩展,php -m 不显示的处理方法
Unity背包系统
verticle-align行内元素垂直居中对齐
Redis implements distributed locks
Integrate SSM to realize search of addition, deletion, modification and query
Version compatibility issues
How to uninstall clean ZABBIX service? (super detailed)
Xctf attack and defense world web master advanced area unserialize3
数字经济已成为最大看点
golang 获取循环嵌套结构的tag
D2dengine edible tutorial (4) -- draw text
每日练习------实现双色球的彩票功能。规则:从36个红球中随机选择不重复的6个数,从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
After reading MySQL database advanced practice (SQL xiaoxuzhu)
Light year admin background management system template
一篇文章掌握Postgresql中对于日期类数据的计算和处理