Halcon 3D平面度
平面度是对表面形状的一种度量,用于指示该表面上的所有点是否都在同一个平面上。平面度在几何尺寸和公差(GD&T)中用平行四边形表示,当两个表面必须装配在一起形成紧密密封时,平面度就特别有用。
使用平面度公差是为了确保某个即定表面位于两个假想的、完美的、平行的平面内。换句话说,公差范围位于被测表面上最高和最低可接受点之间。
测量平面度包括分析一个表面,找出它不完全平坦的程度。为此,首先要在表面上获取一些点,以便找到包括所有这些点的两个平行平面的包络。下一步是找到尽可能小的平面夹层,而不考虑方向(因为这些平面可以在空间自由移动)。最远的两个点之间的距离就是平面度。因此,这两个平面之间的空间越窄,这个平面就越平坦。
read_image (Image, 'E:/项目/蓝膜/3d平面度检测/深度/_2022_08_27_09_33_01.tiff')
dev_close_window ()
get_image_pointer1 (Image, Pointer, Type, Width, Height)
dev_open_window (0, 0, Width/8, Height/8, 'black', WindowHandle1)
dev_display (Image)
X_power:=0.18
Y_power:=0.18
Z_power:=0.0037
Percentage1:=40
Percentage2:=60
Percentage11:=15
Percentage12:=85
dev_get_window (WindowHandle)
dev_set_draw ('margin')
gen_empty_obj (EmptyObject)
for Index1 := 0 to 17 by 1
gen_rectangle2 (Rectangle1, 2290+228*Index1, 719, 0, 300, 60)
concat_obj (EmptyObject, Rectangle1, EmptyObject)
endfor
for Index1 := 0 to 17 by 1
gen_rectangle2 (Rectangle1, 2290+228*Index1, 1757, 0, 300, 60)
concat_obj (EmptyObject, Rectangle1, EmptyObject)
endfor
stop ()
union1 (EmptyObject, RegionUnion)
median_image (Image, ImageMedian, 'square', 17, 'cyclic')
Flatness_ALL (Image, RegionUnion, X_power, Y_power, Z_power, Percentage1, Percentage2, Percentage11, Percentage12, ObjectModel3D, flatness, result)
dev_display (Image)
dev_display (EmptyObject)
try
get_image_size (Image, Width, Height)
gen_image_surface_first_order (ImageX, 'real', X_power, 0, 0, 0, 0, Width, Height)
gen_image_surface_first_order (ImageY, 'real', 0, Y_power, 0, 0, 0, Width, Height)
convert_image_type (Image, ImageConverted, 'real')
scale_image (ImageConverted, ImageZ, Z_power, 0)
reduce_domain (ImageX, ROI_Base, ROI_BaseX)
reduce_domain (ImageY, ROI_Base, ROI_BaseY)
reduce_domain (ImageZ, ROI_Base, ROI_BaseZ)
xyz_to_object_model_3d (ROI_BaseX ,ROI_BaseY,ROI_BaseZ, ObjectModel3D1)
**********************去掉最大最小**************
connection (ROI_Base, ConnectedRegions)
count_obj (ConnectedRegions, Number)
tuple_gen_const (0, 0, Point_X)
tuple_gen_const (0, 0, Point_Y)
tuple_gen_const (0, 0, Point_Z)
****************每个矩形区域滤掉一部分*********************
for Index := 0 to Number-1 by 1
select_obj (ConnectedRegions, ObjectSelected,Index+1)
dev_display (ObjectSelected)
reduce_domain (ImageX, ObjectSelected, ROI_BaseX1)
reduce_domain (ImageY, ObjectSelected, ROI_BaseY1)
reduce_domain (ImageZ, ObjectSelected, ROI_BaseZ1)
xyz_to_object_model_3d (ROI_BaseX1 ,ROI_BaseY1,ROI_BaseZ1, ObjectModel3D1s)
get_object_model_3d_params (ObjectModel3D1s, 'num_points', NumPoints)
get_object_model_3d_params (ObjectModel3D1s, 'point_coord_z' , DistanceDistribution)
tuple_sort (DistanceDistribution, Sorted)
Indexs1:=int(Percentage1*0.01*NumPoints)
Indexs2:=int(Percentage2*0.01*NumPoints)
select_points_object_model_3d (ObjectModel3D1s, 'point_coord_z', Sorted[Indexs1], Sorted[Indexs2], ObjectModel3DThresholded)
get_object_model_3d_params (ObjectModel3DThresholded, 'point_coord_x', BaseX)
get_object_model_3d_params (ObjectModel3DThresholded, 'point_coord_y', BaseY)
get_object_model_3d_params (ObjectModel3DThresholded, 'point_coord_z', BaseZ)
if(Index == 0)
Point_X:=BaseX
Point_Y:=BaseY
Point_Z:=BaseZ
else
Point_X:=[Point_X,BaseX]
Point_Y:=[Point_Y,BaseY]
Point_Z:=[Point_Z,BaseZ]
endif
endfor
gen_object_model_3d_from_points (Point_X, Point_Y, Point_Z, ObjectModel3Ds)
dev_get_window (WindowHandle)
visualize_object_model_3d (WindowHandle, ObjectModel3Ds, [], [], ['lut', 'color_attrib'], ['color1', 'coord_z'], [], [], [], PoseOut)
fit_primitives_object_model_3d (ObjectModel3Ds, ['primitive_type','fitting_algorithm'], ['plane','least_squares'], ObjectModel3DOut)
visualize_object_model_3d (WindowHandle, [ObjectModel3Ds,ObjectModel3DOut], [], [], ['lut', 'color_attrib'], ['color1', 'coord_z'], [], [], [], PoseOut)
get_object_model_3d_params (ObjectModel3DOut, 'primitive_type', GenParamValue)
get_object_model_3d_params (ObjectModel3DOut, 'primitive_parameter', PlaneValue)
get_object_model_3d_params (ObjectModel3DOut, 'point_coord_x', BaseX)
get_object_model_3d_params (ObjectModel3DOut, 'point_coord_y', BaseY)
get_object_model_3d_params (ObjectModel3DOut, 'point_coord_z', BaseZ)
***************************************获取检测点数
tuple_gen_const (0, 0, Points_X)
tuple_gen_const (0, 0, Points_Y)
tuple_gen_const (0, 0, Points_Z)
****************每个矩形区域滤掉一部分*********************
for Index := 0 to Number-1 by 1
select_obj (ConnectedRegions, ObjectSelected,Index+1)
dev_display (ObjectSelected)
reduce_domain (ImageX, ObjectSelected, ROI_BaseX1)
reduce_domain (ImageY, ObjectSelected, ROI_BaseY1)
reduce_domain (ImageZ, ObjectSelected, ROI_BaseZ1)
xyz_to_object_model_3d (ROI_BaseX1 ,ROI_BaseY1,ROI_BaseZ1, ObjectModel3D1s)
get_object_model_3d_params (ObjectModel3D1s, 'num_points', NumPoints)
get_object_model_3d_params (ObjectModel3D1s, 'point_coord_z' , DistanceDistribution)
tuple_sort (DistanceDistribution, Sorted)
Indexs1:=int(Percentage1*0.01*NumPoints)
Indexs2:=int(Percentage2*0.01*NumPoints)
select_points_object_model_3d (ObjectModel3D1s, 'point_coord_z', Sorted[Indexs1], Sorted[Indexs2], ObjectModel3DThresholded)
get_object_model_3d_params (ObjectModel3DThresholded, 'point_coord_z', BaseZ)
tuple_median (BaseZ, TupleZ)
area_center (ObjectSelected, Area, TupleX, TupleY)
if(Index == 0)
Points_X:=TupleX
Points_Y:=TupleY
Points_Z:=TupleZ
else
Points_X:=[Points_X,TupleX]
Points_Y:=[Points_Y,TupleY]
Points_Z:=[Points_Z,TupleZ]
endif
endfor
fit_3d_plane_xyz (Points_X, Points_Y, Points_Z, Ox, Oy, Oz, Nx, Ny, Nz, MeanResidual)
*平面度 *点到面的距离 计算base面的平面度
d1:=(Nx*Points_X+Ny*Points_Y+Nz*Points_Z-PlaneValue[3])
tuple_sort (d1, Sorted1)
flatness:=max(d1)-min(d1)
result:=1
catch (Exception)
result:=-1
endtry
return ()
原文地址:https://blog.csdn.net/2202_75557553/article/details/143788461
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!