当前位置:网站首页>【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
边栏推荐
- 动态内存管理中的malloc、free、calloc、realloc动态内存开辟函数
- deepstream 检测结果截图
- 如何卸载干净zabbix服务?(超详细)
- SSM integration (integrated configuration)
- Outlook tutorial, how to use color categories and reminders in outlook?
- Redis persistence mechanism
- 【论文笔记】基于深度学习的移动机器人自主导航实验平台
- Embedded database -- SQLite
- Billions of asset addresses are blacklisted? How to use the tether address freezing function?
- Volvo: what on earth does the deep-rooted "sense of security" rely on?
猜你喜欢

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

动态内存管理中的malloc、free、calloc、realloc动态内存开辟函数

Analysis of redis network model

How to solve the problem of win11 black desktop background?

鼠标操作和响应

Billions of asset addresses are blacklisted? How to use the tether address freezing function?

沃尔沃:深入人心的“安全感” 究竟靠的是什么?

Illustrated: detailed explanation of JVM memory layout

Summary of concurrent programming interview questions

Shell:一键部署pxe
随机推荐
动态内存管理中的malloc、free、calloc、realloc动态内存开辟函数
【论文笔记】基于深度学习的移动机器人自主导航实验平台
沃尔沃:深入人心的“安全感” 究竟靠的是什么?
Win11 how to rename an audio device
最新版宝塔安装zip扩展,php -m 不显示的处理方法
Super nice PHP program source code of nteam official website
MySQL事务的ACID特性及并发问题实例分析
4天Excel实战训练营,0.01元特惠仅三天,赠200套学习资料包
Version compatibility issues
光年(Light Year Admin)后台管理系统模板
The open source of "avoiding disease and avoiding medicine" will not go far
Summary of concurrent programming interview questions
Responsive high-end website template source code Gallery material resource download platform source code
Shell编写规范和变量
How does win11 display fixed applications?
Prefix-Tuning: Optimizing Continuous Prompts for Generation
MangoPapa 的实用小脚本(目录篇)
Log analysis tool (Splunk)
动态规划——62. 不同路径
Digital economy has become the biggest attraction