目录
- 一、inspect_3d_surface_intersections代码第一部分
- 二、inspect_3d_surface_intersections代码第二部分
- 三、inspect_3d_surface_intersections代码第三部分
一、inspect_3d_surface_intersections代码第一部分
1、创建一个未标定的激光三角测量模型
2、获得参考3D Model,创建一个基于表面匹配的模板
NumDisparityProfiles := 441
read_image (DisparityProfile, 'sheet_of_light/metal_part_1_disparity_line_000')
create_sheet_of_light_model (DisparityProfile, 'calibration', 'offset_scale', SheetOfLightModelID)
ScaleX := 1
ScaleY := 4
ScaleZ := 0.5
set_sheet_of_light_param (SheetOfLightModelID, 'scale_x', ScaleX)
set_sheet_of_light_param (SheetOfLightModelID, 'scale_y', ScaleY)
set_sheet_of_light_param (SheetOfLightModelID, 'scale_z', ScaleZ)set_profile_sheet_of_light (ImageModel, SheetOfLightModelID, [])
get_sheet_of_light_result_object_model_3d (SheetOfLightModelID, Model3DFull)
surface_normals_object_model_3d (Model3D, 'mls', 'mls_force_inwards', 'true', ObjectModel3DNormals)
triangulate_object_model_3d (ObjectModel3DNormals, 'greedy', 'greedy_remove_small_surfaces', 200, ObjectModel3DReference, Information)
create_surface_model (ObjectModel3DReference, 0.03, 'model_invert_normals', 'true', SurfaceModelID)
二、inspect_3d_surface_intersections代码第二部分
1、创建三个平面
2、将3D对象模型与平面相交
3、确定交点并将其转换为 XLD 轮廓
create_pose (300, 230, 250, -90, 0, 0, 'Rp+T', 'gba', 'point', PoseIntersectionPlane1)
create_pose (300, 900, 250, -90, 0, 0, 'Rp+T', 'gba', 'point', PoseIntersectionPlane2)
create_pose (300, 1570, 250, -90, 0, 0, 'Rp+T', 'gba', 'point', PoseIntersectionPlane3)
gen_plane_object_model_3d (PoseIntersectionPlane1, [-1, -1, 1, 1] * VisualizationPlaneSize, [-1, 1, 1, -1] * VisualizationPlaneSize, IntersectionPlane1)
gen_plane_object_model_3d (PoseIntersectionPlane2, [-1, -1, 1, 1] * VisualizationPlaneSize, [-1, 1, 1, -1] * VisualizationPlaneSize, IntersectionPlane2)
gen_plane_object_model_3d (PoseIntersectionPlane3, [-1, -1, 1, 1] * VisualizationPlaneSize, [-1, 1, 1, -1] * VisualizationPlaneSize, IntersectionPlane3)intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane1, ObjectModel3DIntersection1)
intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane2, ObjectModel3DIntersection2)
intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane3, ObjectModel3DIntersection3)project_object_model_3d_lines_to_contour_xld (Intersection1, PoseIntersectionPlane1, ObjectModel3DIntersection1)
project_object_model_3d_lines_to_contour_xld (Intersection2, PoseIntersectionPlane2, ObjectModel3DIntersection2)
project_object_model_3d_lines_to_contour_xld (Intersection3, PoseIntersectionPlane3, ObjectModel3DIntersection3)
*
* Determine the nominal dimensions and the tolerance limits by
* analysing the measurements from the reference sample
OrientationRef := 20
OrientationTolerance := 20
analyze_intersection (Intersection1, FittedLines1, OrientationRef, OrientationTolerance, MinDistance1, MaxDistance1, Angle1)
analyze_intersection (Intersection2, FittedLines2, OrientationRef, OrientationTolerance, MinDistance2, MaxDistance2, Angle2)
analyze_intersection (Intersection3, FittedLines3, OrientationRef, OrientationTolerance, MinDistance3, MaxDistance3, Angle3)
*
下面是函数project_object_model_3d_lines_to_contour_xld (Intersection, PoseIntersectionPlane, ObjectModel3DIntersection)的实现过程
1、获取三维点集的直径,定义为最小外接轴平行长方体的对角线长度。
2、这里PoseIntersectionPlane为什么要invert:
输入的是PoseIntersectionPlane,平面在模型坐标系的姿态,取反就是模型在平面坐标系的姿态,平面坐标系,z上加个diameter看作相机坐标系。就是保证投影平面在相机前。这里其实随意加个数就可以,因为使用的是远心镜头参数,相当于垂直于这个平面去看这个轮廓。平面的中心对应图像中心原点。
3、采用分式模型生成一个远心镜头相机参数。
4、将一个三维物体模型投影到图像坐标系中.
pose_invert (PoseIntersectionPlane, PoseInvert)
get_object_model_3d_params (ObjectModel3DIntersection, 'diameter_axis_aligned_bounding_box', Diameter)
PoseInvert[2] := PoseInvert[2] + DiameterScale := 1
gen_cam_par_area_scan_telecentric_division (1.0, 0, 1.0 / Scale, 1.0 / Scale, 0, 0, 512, 512, CamParam)
project_object_model_3d (Intersection, ObjectModel3DIntersection, CamParam, PoseInvert, 'data', 'lines')
return ()
三、inspect_3d_surface_intersections代码第三部分
1、根据激光三角测量模型,获得3D模型,表面匹配,把平面变换到当前3D场景中。
2、获得模型和平面相机部分,投影到图像上,进行轮廓分析。
reset_sheet_of_light_model (SheetOfLightModelID)
read_image (ImageSearch, 'sheet_of_light/metal_part_' + (SceneIndex + 1) + '_disparity_line_' + Index$'03d')
set_profile_sheet_of_light (ImageSearch, SheetOfLightModelID, [])
get_sheet_of_light_result_object_model_3d (SheetOfLightModelID, Scene3DFull)
get_object_model_3d_params (Scene3DFull, 'bounding_box1', BoundingBox1)
MaxZ := BoundingBox1[5]
select_points_object_model_3d (Scene3DFull, 'point_coord_z', MinZ, MaxZ, Scene3D)
find_surface_model (SurfaceModelID, Scene3D, 0.005, 0.2, 0, 'false', [], [], Pose, Score, SurfaceMatchingResultID)
* Align the intersection planes to the test object
rigid_trans_object_model_3d (IntersectionPlane1, Pose, IntersectionPlane1Aligned)
rigid_trans_object_model_3d (IntersectionPlane2, Pose, IntersectionPlane2Aligned)
rigid_trans_object_model_3d (IntersectionPlane3, Pose, IntersectionPlane3Aligned)
get_object_model_3d_params (IntersectionPlane1Aligned, 'primitive_parameter_pose', IntersectionPlane1AlignedPose)
get_object_model_3d_params (IntersectionPlane2Aligned, 'primitive_parameter_pose', IntersectionPlane2AlignedPose)
get_object_model_3d_params (IntersectionPlane3Aligned, 'primitive_parameter_pose', IntersectionPlane3AlignedPose)disp_message (WindowHandle, Message[0:2], 'window', 12, 12, 'black', 'true')
triangulate_object_model_3d (Scene3D, 'greedy', [], [], Scene3DTest, Information)
dev_clear_window ()
disp_object_model_3d (WindowHandle, [Scene3DTest,IntersectionPlane1Aligned,IntersectionPlane2Aligned,IntersectionPlane3Aligned], VisualizationCamParam, VisualizationPose, ['color_1', 'color_2', 'color_3', 'alpha', 'alpha_0'], [VisualizationColors,0.75, 1])
Message := 'Test object ' + SceneIndex + ' with aligned intersection planes'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,25})\\s', 'replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 12, 'black', 'true')intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane1AlignedPose, ObjectModel3DIntersection1)
intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane2AlignedPose, ObjectModel3DIntersection2)
intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane3AlignedPose, ObjectModel3DIntersection3)project_object_model_3d_lines_to_contour_xld (Intersection1, IntersectionPlane1AlignedPose, ObjectModel3DIntersection1)
project_object_model_3d_lines_to_contour_xld (Intersection2, IntersectionPlane2AlignedPose, ObjectModel3DIntersection2)
project_object_model_3d_lines_to_contour_xld (Intersection3, IntersectionPlane3AlignedPose, ObjectModel3DIntersection3)analyze_intersection (Intersection1, FittedLines1, OrientationRef, OrientationTolerance, MinDistance1, MaxDistance1, Angle1)
analyze_intersection (Intersection2, FittedLines2, OrientationRef, OrientationTolerance, MinDistance2, MaxDistance2, Angle2)
analyze_intersection (Intersection3, FittedLines3, OrientationRef, OrientationTolerance, MinDistance3, MaxDistance3, Angle3)