Halcon——矩阵/Matrix

1.矩阵创建

create_matrix — Create a matrix. 创建一个矩阵

create_matrix( : : Rows, Columns, Value : MatrixID)

A.创建一个3*3单位矩阵  

  create_matrix(3,3,'iidentity',MatrixID)

B.创建一个值均为7的3*3方阵

  create_matrix(3,3,7,MatrixID)

 

C.创建一个3*4矩阵

  create_matrix(3,4,[3,7,1],MatrixID)

 

D.创建一个3*3矩阵

  create_matrix(3,4,[3,1,-2,-5,7,2,-9,-4,1],MatrixID)

2.矩阵操作

2.1  set_sub_matrix — Set a sub-matrix of a matrix. 设置矩阵的子矩阵

set_sub_matrix( : : MatrixID, MatrixSubID, Row, Column : )

城实现过程:

2.2 solve_matrix — Compute the solution of a system of equations    计算方程组的解(计算线性方程组或线性最小二乘问题的解)

复制代码
* This example programs shows how to use matrices in HALCON to
* solve a system of equations.
* The example generates a sequence of random points and fits
* a quadratic function to these points.
* 此示例程序展示了如何使用 HALCON 中的矩阵来
* 求解方程组。
* 该示例生成一系列随机点并拟合
* 这些点的二次函数。
dev_update_off ()
dev_close_window ()
Size := 500
dev_open_window (0, 0, Size, Size, 'white', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_part (0, 0, Size - 1, Size - 1)
* 
* Create a set of random points which lie approximately on
* a second order curve
* 创建一组随机点,这些点大约位于
* 二阶曲线
* 
X := [25:50:Size]
Y := 15 + 0.4 * X + 0.001 * X * X
* Y := Y + 40 * rand(|Y|)
* 
* Show the point set
* 
gen_cross_contour_xld (Cross, Size - Y, X, 15, 0.785398)
dev_set_color ('blue')
dev_set_line_width (3)
dev_display (Cross)
disp_message (WindowHandle, 'Input point sequence', 'window', 70, 25, 'blue', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Now fit these points to a quadratic function of the form
* 
* f(x) = a*x^2 + b*x + c
* 
* This can be achieved by solving the system of equations
* 
* Ax = B
* 
* where each line in A consists of [X^2, X, 1],
* and each line of B consist of the corresponding Y value
* 
* If this system of equations is solved for x, x will contain
* the parameters of the quadratic function:
* 
* x = [a, b, c]

**
* 现在将这些点拟合为形式的二次函数
*
* f(x) = a*x^2 + b*x + c
*
* 这可以通过求解方程组来实现
*
* Ax = B
*
* 其中 A 中的每一行由 [X^2, X, 1] 组成,
* B 的每一行由相应的 Y 值组成
*
* 如果求解 x 的方程组,则 x 将包含
* 二次函数的参数:
*
* x = [a, b, c]
*
* 
create_matrix (|X|, 3, 1.0, MatrixA)
create_matrix (|X|, 1, X, MatrixACol1)
create_matrix (|X|, 1, X * X, MatrixACol0)
set_sub_matrix (MatrixA, MatrixACol1, 0, 1)
set_sub_matrix (MatrixA, MatrixACol0, 0, 0)
* 
create_matrix (|X|, 1, Y, MatrixB)
solve_matrix (MatrixA, 'general', 0, MatrixB, MatrixX)
* 
* Plot the approximated quadratic function
*绘制近似二次函数
* 
Sequence := [0:1200]
get_value_matrix (MatrixX, 0, 0, A)
get_value_matrix (MatrixX, 1, 0, B)
get_value_matrix (MatrixX, 2, 0, C)
Distances := A * Sequence * Sequence + B * Sequence + C
gen_contour_polygon_xld (Contour, Size - Distances, Sequence)
dev_set_color ('forest green')
dev_display (Contour)
Message := 'Approximated quadratic function'
Message[1] := 'f(x) = ' + A$'.2' + '*x^2 + ' + B$'.2' + '*x + ' + C$'.2' + ''
disp_message (WindowHandle, Message, 'window', 100, 25, 'forest green', 'false')
disp_end_of_program_message (WindowHandle, 'black', 'true')
复制代码

 2.3 mult_element_matrix — Multiply matrices element-by-element.   计算矩阵的哈达玛积(基本积)

         矩阵逐元素相乘

  

 

2.4 add_matrix_mod — Add two matrices.     

  矩阵逐元素相加

2.5 sub_matrix — Subtract two matrices.

  矩阵逐元素相减

  

2.6 mult_matrix — Multiply two matrices.   两个矩阵相乘

  mult_matrix( : : MatrixAID, MatrixBID, MultType : MatrixMultID) 

  ********MultType ='AB'时  

    

********MultType ='ATB'时

 

********MultType ='ABT'时 

********MultType ='ATBT'时 

 

2.7 invert_matrix — Invert a matrix.     获取矩阵逆

 

 

 

2.8  scale_matrix — Scale a matrix.

 2.9  pow_scalar_element_matrix — Compute the power functions of the elements of a matrix.

 2.10  mean_matrix — Returns the elementwise mean of a matrix.  返回矩阵的元素均值。

    mean_matrix( : : MatrixID, MeanType : MatrixMeanID)

    

 

 

 

2.11  sqrt_matrix_mod — Compute the square root values of the elements of a matrix. 计算矩阵元素的平方根值

 2.12  get_full_matrix — Return all values of a matrix.   返回矩阵的所有值

 2.13  set_value_matrix — Set one or more elements of a matrix.

 

posted @   echo-efun  阅读(465)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示