Halcon 3D moments_object_model_3d简介

42 篇文章 18 订阅

一、矩简介

Opencv 笔记11 图像的矩原理解析_Σίσυφος1900的博客-CSDN博客_opencv 图像的矩

矩是概率与统计中的一个概念,假设有随机变量X,常数c,正整数k,则有

E[(X−c)k]称X为c 的k阶矩。

1.c=0->ak=E(Xk)称为X的k阶原点矩

2. c=E(X)。这时μk=E[(X−EX)k]称为X的k阶中心矩。(这个是我们经常使用的)

同理当随机变量是X 、Y的二维时候有如下:

1、A1=A2=0->上式称为X的p+q阶混合原点矩

2.  A1=E(X),A2=E(Y)->上式称为X的p+q阶混合中心矩

 二、算子演示

disp_object_model_3d显示模型

GenParamName := ['lut','color_attrib','light_position','disp_pose','alpha']

GenParamValue := ['color1','coord_z','0.0 0.0 -0.3 1.0','true',0.9]

disp_object_model_3d (WindowHandle1, ObjectModel3D, [], DispPose1, GenParamName, GenParamValue)

*案例

GenParamName := ['lut','intensity','light_position','disp_pose','alpha']
GenParamValue := ['color1','coord_z','0.0 0.0 -0.3 1.0','true',0.9]
        'lut':渐变色        
        'intensity':沿着哪个方向改变颜色        
        'light_position':光照位置
        'disp_pose', 是否显示坐标轴
        'alpha':与透明度123456



color_attrib :'none'、'&distance'、'coord_x'、'coord_y'、'coord_z'、用户定义的点属性或任何其他可用的点属性。
设置为 'coord_z',并且 'lut' 设置为 'color1',则 z 坐标的颜色编码将从红色变为蓝色。
如果 'lut' 设置为 'default',则属性值用于缩放由参数 'color' 设置的颜色。
如果 'lut' 设置为不同的值,则所有点的属性值在内部缩放到区间 [0,255] 并用作 LUT 函数的输入值。

moments_object_model_3d 计算3D模型的一阶、二阶矩

moments_object_model_3d (ObjectModel3D, 'central_moment_2_points', Moments)

第二个参数: 'central_moment_2_points', 'mean_points', 'principal_axes'


mean_points: 表示的均值,可以理解为一阶中心矩,返回值是三个数字,分别是点云在x,y,z 轴的均值


central_moment_2_points: 表示的是方程,可以理解为二阶矩(表示的是浮动情况)  --结果是 x、y、z表示电云在各个轴上的波动情况(方差),x-y、x-z 和 y-z 轴的协方差,可以理解为点云在各个轴上的相关性【-1,1】)。

principal_axes:计算 3D 对象模型的三个主轴,结果是一个以点的平均值为中心的姿势。
对应于姿势的坐标系具有沿第一主轴的x轴、沿第二主轴的y轴和沿第三主轴的z轴。

 

moments_object_model_3d (ObjectModel3D, 'central_moment_2_points', Moments)

第二个参数: 'central_moment_2_points', 'mean_points', 'principal_axes'


mean_points: 表示的均值,可以理解为一阶中心矩,返回值是三个数字,分别是点云在x,y,z 轴的均值


central_moment_2_points: 表示的是方程,可以理解为二阶矩(表示的是浮动情况)  --结果是 x、y、z表示电云在各个轴上的波动情况(方差),x-y、x-z 和 y-z 轴的协方差,可以理解为点云在各个轴上的相关性【-1,1】)。

principal_axes:计算 3D 对象模型的三个主轴,结果是一个以点的平均值为中心的姿势。
对应于姿势的坐标系具有沿第一主轴的x轴、沿第二主轴的y轴和沿第三主轴的z轴。

 

 三、代码演示

* 
* Object models e.g. acquired with a 3D sensor can have an object
* coordinate system, that is not aligned with the major axes of
* the object. If the object has a ridge, it is desirable that the
* object coordinate system is aligned with this ridge, e.g. that
* the x-axis indicates the direction of the ridge.
* 
* This example demonstrates the use of the operator
* moments_object_model_3d to align 3D data with the x-, y-, z-
* coordinate axes.
* The operator can be used to determine the mean of all points of
* a 3d object model. Furthermore, the operator can be used to
* extract the principal axes of the model. The main principal axis
* is the axis along which the variance of the data is largest.
* If the 3D object model is transformed into the principal axes
* coordinate system, the x-axis corresponds to the first principal
* axes. The y-axis is the second principal axes. And the z-axis
* is the third principal axes.
* 
* Prepare the main window
dev_close_window ()
FontSize := 14
WindowSize := 500
dev_open_window (0, 0, WindowSize, WindowSize, 'white', WindowHandle1)
set_display_font (WindowHandle1, FontSize, 'mono', 'true', 'false')
* 
* Set visualization parameters for the 3d object model
* A lookup table (lut) is set that transforms attribute values into
* a color. In this example the color encodes the value of the
* z-component of the data. The alpha parameter defines the
* transparency of the object model.
GenParamName := ['lut','color_attrib','light_position','disp_pose','alpha']
*lut 表示的是
GenParamValue := ['color1','coord_z','0.0 0.0 -0.3 1.0','true',0.9]
* Define factor for scaling meter to millimeters
Scale2Millimeter := 1000
* Read the 3d object model from file
read_object_model_3d ('cutting_edge.om3', 'm', [], [], ObjectModel3D, Status)
* Define the poses from which the camera looks at the object model
create_pose (-0.0005, -0.0005, 0.04, 280, 0, 20, 'Rp+T', 'gba', 'point', DispPose1)
create_pose (0, -0.0005, 0.04, 280, 0, 20, 'Rp+T', 'gba', 'point', DispPose2)
* 
* Display introduction text
Information := 'This example shows how an object coordinate'
Information[1] := 'system can be aligned with the data given by'
Information[2] := 'a 3D object model.'
Information[3] := ' '
Information[4] := 'This may be useful, e.g. to align a cutting'
Information[5] := 'edge in a way that the x-axis indicates the'
Information[6] := 'direction of the ridge.'
disp_message (WindowHandle1, Information, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()
* 
* Visualize the 3d object model and its object coordinate system.
* The original coordinate axes are not aligned with the main axes
* of the data. The object coordinate system is shown with the
* x-axis in red, the y-axis in green and the z-axis in blue.
* The color of an object model point is determined by its z-coordinate.
* Thus, the color of the object model shows that points along the
* ridge of the object have different z-coordinates.
dev_set_window (WindowHandle1)
dev_clear_window ()
WindowTitle := 'The coordinate axes of the object model are'
WindowTitle[1] := 'not aligned with the main axes of the model.'
WindowTitle[2] := 'The coloring of the model shows that points'
WindowTitle[3] := 'along the top ridge of the object have '
WindowTitle[4] := 'different z-coordinates.'
disp_object_model_3d (WindowHandle1, ObjectModel3D, [], DispPose1, GenParamName, GenParamValue)
disp_message (WindowHandle1, WindowTitle, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()
dev_open_window (0, WindowSize + 13, WindowSize, WindowSize, 'white', WindowHandle2)
set_display_font (WindowHandle2, FontSize, 'mono', 'true', 'false')
* 
* Compute the principal axes system for the 3d object model
* where the axes represent the directions largest variance.
* Transform the object model into the computed new
* coordinate system.
* 
* The pose returned by moments_object_model_3d describes
* the principal axes coordinate system with respect to
* the original coordinate system of the 3D object model.
* The origin of the principal axes coordinate system is identical with
* the mean point of the object model.
moments_object_model_3d (ObjectModel3D, 'principal_axes', Pose)

moments_object_model_3d (ObjectModel3D, 'mean_points', Posesss)
* Transform the 3D object model into its principal axes
* coordinate system.
* For transforming the points of the 3D object model into the
* principal axes coordinate system, the inverse of the computed
* pose is needed.
pose_invert (Pose, PoseInvert)
pose_to_hom_mat3d (PoseInvert, HomMat3D)
affine_trans_object_model_3d (ObjectModel3D, HomMat3D, ObjectModel3DPCA)
* Compute the moments of second order for the original model.
* These moments correspond to the variances in x, y, z and the
* covariances xy, xz and yz.
moments_object_model_3d (ObjectModel3D, 'central_moment_2_points', Moments)
* Extract the variance along the x, y, z axes (scaled to mm²)
MomentsSecondOrderOrig := Moments[0:2] * (Scale2Millimeter * Scale2Millimeter)
* Compute the moments of second order for the transformed model
moments_object_model_3d (ObjectModel3DPCA, 'central_moment_2_points', MomentsPCA)
* Extract the variance along the x, y, z axes (scaled to mm²)
MomentsSecondOrderPCA := MomentsPCA[0:2] * (Scale2Millimeter * Scale2Millimeter)
* 
* Display results
WindowTitle := 'The 3D object model was transformed into its'
WindowTitle[1] := 'principal axes system. The object model is'
WindowTitle[2] := 'now aligned with the coordinate axes.'
* Compare the variances along the x, y, z axis in
* the old and in the new object coordinate system.
* For the principal axes system, it can be seen that
* the largest variance in the data is concentrated
* along the x-axis. The second largest variance
* occurs along the y-axis.
OldVariance[0] := 'Variances in original system:'
OldVariance[1] := ' '
OldVariance[2] := '  Var(x) = ' + MomentsSecondOrderOrig[0]$'.3f' + ' mm²'
OldVariance[3] := '  Var(y) = ' + MomentsSecondOrderOrig[1]$'.3f' + ' mm²'
OldVariance[4] := '  Var(z) = ' + MomentsSecondOrderOrig[2]$'.3f' + ' mm²'
* Variances for the object model in the new coordinate system
NewVariance[0] := 'Variances in new system:'
NewVariance[1] := ' '
NewVariance[2] := '  Var(x) = ' + MomentsSecondOrderPCA[0]$'.3f' + ' mm²'
NewVariance[3] := '  Var(y) = ' + MomentsSecondOrderPCA[1]$'.3f' + ' mm²'
NewVariance[4] := '  Var(z) = ' + MomentsSecondOrderPCA[2]$'.3f' + ' mm²'
disp_object_model_3d (WindowHandle2, ObjectModel3DPCA, [], DispPose2, GenParamName, GenParamValue)
disp_message (WindowHandle2, WindowTitle, 'window', 12, 12, 'black', 'false')
disp_message (WindowHandle2, NewVariance, 'window', 350, 12, 'black', 'false')
disp_message (WindowHandle1, OldVariance, 'window', 350, 12, 'black', 'false')
stop ()
disp_end_of_program_message (WindowHandle1, 'black', 'true')

  • 0
    点赞
  • 2
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:代码科技 设计师:Amelia_0503 返回首页
评论

打赏作者

Σίσυφος1900

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值