当前位置:网站首页>【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 make the Internet access the intranet IP (used by esp8266 web pages)
- 53. Maximum subarray maximum subarray sum
- 动态规划——62. 不同路径
- 超好看的Nteam官网PHP程序源码
- MySQL stored procedures use cursors to synchronize data between two tables
- IronOCR for .NET 2022.8
- What are the fragments of MySQL
- Asemi rectifier bridge gbpc5010, gbpc5010 parameters, gbpc5010 size
- Shell: one click deployment PXE
- MySQL的碎片有哪些
猜你喜欢

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

How to uninstall clean ZABBIX service? (super detailed)

⽇志分析⼯具(Splunk)

How to solve the problem of win11 black desktop background?

Practice of online problem feedback module (16): realize the function of checking details

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

Asemi rectifier bridge gbpc5010, gbpc5010 parameters, gbpc5010 size

最新版宝塔安装zip扩展,php -m 不显示的处理方法

Mouse operation and response

The open source of "avoiding disease and avoiding medicine" will not go far
随机推荐
Win11 how to rename an audio device
LabVIEW加载和使用树型控件项目中的定制符号
8000字讲透OBSA原理与应用实践
最新版宝塔安装zip扩展,php -m 不显示的处理方法
IronOCR for .NET 2022.8
2022 summary of the latest Android handler related interview questions
ES6 从入门到精通 # 07:解构赋值
Billions of asset addresses are blacklisted? How to use the tether address freezing function?
Robot development -- lead screw and guide rail
【5G NR】RRC Reject解析
golang gorm查询任意字段的组装方法
MySQL stored procedures use cursors to synchronize data between two tables
Color recognition method and exploration based on MATLAB
redis源码分析(谁说C语言就不能分析了?)
Redis memory recycling
VMware虚拟机网络设置
Unity simply implements the dialog function
203. Remove linked list elements
Golang gets the tag of the loop nested structure
D2DEngine食用教程(4)———绘制文本