目录
- 代码示例
- 代码示例的逐句解释
以下是halcon中的代码示例
* This example shows the inspection of planar intersections of
* 3D objects. The intersections are derived by intersecting the
* reconstructed 3D object models with suitable planes, using the
* operator intersect_plane_object_model_3d.
*
* The objects, which are metal parts in this example, are
* scanned with an uncalibrated sheet of light setup that returns
* disparities for each scan line. The disparities are
* transformed into a 3D object model. In this example, the
* transformation is based on simple scalings of the three
* dimensions that were chosen such that the reconstructed 3D
* object model is given approximately in mm.
*
* The nominal dimensions and the tolerance limits are derived
* from a reference sample of the metal part. For this,
* intersections derived at predefined positions are analysed.
* Note that if the nominal dimension and tolerance limits should
* be specified numerically, the reconstruction must be done with
* a fully calibrated setup to ensure that the specified values
* are meaningfull with respect to the reconstructed 3D object
* model.
*
* For the inspection, 3D object models of the metal parts are
* reconstructed in the same way as described for the reference
* sample. With the help of surface based matching, the
* intersection planes, which are defined with respect to the
* reference sample, are aligned with the parts to be inspected.
* The resulting intersections are then analysed to check whether
* the dimensions of the objects to be inspected are within the
* allowed tolerance limits.
*
*
*
* Part 1: Reconstruction of the reference sample and derivation
* of nominal dimensions and tolerance limits
*
* Set up the sheet of light 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)
* Set the scaling factors for the calibration method 'offset_scale'
* such that the reconstructed 3D object model is given approximately
* in mm
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)
*
* Define the z coordinate at which the object can be separated from
* the background
MinZ := 220
*
* Initialize display
dev_update_off ()
set_system ('clip_region', 'false')
dev_close_window ()
get_image_size (DisparityProfile, DisparityProfileWidth, DisparityProfileHeight)
WindowEnlargement := 350
WindowWidth := DisparityProfileWidth + WindowEnlargement
WindowHeight := NumDisparityProfiles
dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle)
dev_set_part (0, 0, WindowHeight - 1, WindowWidth - 1)
get_part (WindowHandle, PartRow1, PartColumn1, PartRow2, PartColumn2)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw ('fill')
*
* Define some visualization parameters
VisualizationPlaneSize := 150
gen_cam_par_area_scan_division (0.01, 0, 6e-6, 6e-6, WindowWidth / 2, WindowHeight / 2, WindowWidth, WindowHeight, VisualizationCamParam)
create_pose (-1550, 680, 5390, 122, 1, 357, 'Rp+T', 'gba', 'point', VisualizationPose)
VisualizationColors := ['magenta','blue','orange']
*
* Create the reference sample by collecting the measured
* disparity profiles in a sheet-of-light model and
* transforming them to a 3D object model
gen_image_const (DisparityImageVis, 'uint2', DisparityProfileWidth, NumDisparityProfiles)
for Index := 0 to NumDisparityProfiles - 1 by 1
* Add the next disparity profile to the sheet of light model
read_image (ImageModel, 'sheet_of_light/metal_part_1_disparity_line_' + Index$'03d')
set_profile_sheet_of_light (ImageModel, SheetOfLightModelID, [])
* Accumulated profiles for visualization
get_grayval (ImageModel, gen_tuple_const(DisparityProfileWidth,0), [0:DisparityProfileWidth - 1], Disparities)
set_grayval (DisparityImageVis, gen_tuple_const(DisparityProfileWidth,Index), [0:DisparityProfileWidth - 1], Disparities)
if (Index % 5 == 4)
dev_display (DisparityImageVis)
Message := 'Disparity image of the reference sample'
Message[1] := 'Adding disparity profile ' + (Index + 1) + '/' + NumDisparityProfiles
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
endif
endfor
* Display the disparity image of the reference sample
dev_display (DisparityImageVis)
disp_message (WindowHandle, 'Disparity image of the reference sample', 'window', 12, 12, 'black', 'true')
* Get the 3D reconstruction of the reference sample and eliminate
* the background from the respective 3D object model
get_sheet_of_light_result_object_model_3d (SheetOfLightModelID, Model3DFull)
get_object_model_3d_params (Model3DFull, 'bounding_box1', BoundingBox1)
MaxZ := BoundingBox1[5]
select_points_object_model_3d (Model3DFull, 'point_coord_z', MinZ, MaxZ, Model3D)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Prepare the 3D object model for the intersection with
* the planes and to allow the alignment of the intersection
* planes to the objects to be inspected
dev_clear_window ()
dev_set_part (PartRow1, PartColumn1, PartRow2, PartColumn2)
disp_object_model_3d (WindowHandle, Model3D, VisualizationCamParam, VisualizationPose, [], [])
Message := 'Prepare the reference model'
Message[1] := ' - triangulate 3D object model and'
Message[2] := ' - create surface model for alignment'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* Triangulate the 3D object model
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 a surface model for alignment
create_surface_model (ObjectModel3DReference, 0.03, 'model_invert_normals', 'true', SurfaceModelID)
*
* Define the intersection planes relative to the reference sample,
* calculate the intersections and derive nominal dimensions and
* tolerance limits from these intersections
*
* Define the intersection planes
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)
dev_clear_window ()
dev_set_part (PartRow1, PartColumn1, PartRow2, PartColumn2)
disp_object_model_3d (WindowHandle, [ObjectModel3DReference,IntersectionPlane1,IntersectionPlane2,IntersectionPlane3], VisualizationCamParam, VisualizationPose, ['color_1','color_2','color_3','alpha','alpha_0'], [VisualizationColors,0.75,1])
Message := 'Reference sample with predefined intersection planes'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,25})\\s','replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 12, 'black', 'true')
*
* Calculate the intersections of the reference sample with the above
* defined planes
intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane1, ObjectModel3DIntersection1)
intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane2, ObjectModel3DIntersection2)
intersect_plane_object_model_3d (ObjectModel3DReference, PoseIntersectionPlane3, ObjectModel3DIntersection3)
*
* Determine the intersections and convert them into XLD contours
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)
*
* Visualize the object with the intersection planes and the respective
* intersections and measurement results
hom_mat2d_identity (HomMat2DIdentity)
* Display explanations
Message := 'Intersections with measurement lines'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,20})\\s','replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 330, 'black', 'true')
Message := 'Measurement results'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,20})\\s','replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 590, 'black', 'true')
* Display first intersection
hom_mat2d_translate (HomMat2DIdentity, 350, 390, HomMat2DTranslate1)
affine_trans_contour_xld (Intersection1, Intersection1Vis, HomMat2DTranslate1)
affine_trans_contour_xld (FittedLines1, FittedLines1Vis, HomMat2DTranslate1)
dev_set_color (VisualizationColors[0])
dev_set_line_width (5)
dev_display (Intersection1Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines1Vis)
Message := 'Angle = ' + Angle1$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance1$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance1$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 310, 600, VisualizationColors[0], 'false')
* Display second intersection
hom_mat2d_translate (HomMat2DIdentity, 250, 410, HomMat2DTranslate2)
affine_trans_contour_xld (Intersection2, Intersection2Vis, HomMat2DTranslate2)
affine_trans_contour_xld (FittedLines2, FittedLines2Vis, HomMat2DTranslate2)
dev_set_color (VisualizationColors[1])
dev_set_line_width (5)
dev_display (Intersection2Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines2Vis)
Message := 'Angle = ' + Angle2$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance2$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance2$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 210, 600, VisualizationColors[1], 'false')
* Display third intersection
hom_mat2d_translate (HomMat2DIdentity, 150, 430, HomMat2DTranslate3)
affine_trans_contour_xld (Intersection3, Intersection3Vis, HomMat2DTranslate3)
affine_trans_contour_xld (FittedLines3, FittedLines3Vis, HomMat2DTranslate3)
dev_set_color (VisualizationColors[2])
dev_set_line_width (5)
dev_display (Intersection3Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines3Vis)
Message := 'Angle = ' + Angle3$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance3$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance3$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 110, 600, VisualizationColors[2], 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Define the nominal dimensions and the tolerance limits based
* on the measurements of the reference sample
AngleRef := mean([Angle1,Angle2,Angle3])
MaxAngleDev := 2
MinAngle := AngleRef - MaxAngleDev
MaxAngle := AngleRef + MaxAngleDev
MinDistance := 0.95 * mean([MinDistance1,MinDistance2,MinDistance3])
MaxDistance := 1.05 * mean([MaxDistance1,MaxDistance2,MaxDistance3])
* Display the nominal dimensions and the tolerance limits
dev_clear_window ()
Message := 'Tolerance limits for the angle and the distance of the mounting tabs, derived from the three measurements on the reference sample:'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,75})\\s','replace_all'],'$1\n')
Message := MessageWrapped
Message[1] := ' '
Message[2] := 'Min Angle = ' + MinAngle$'.1f' + ' deg'
Message[3] := 'Max Angle = ' + MaxAngle$'.1f' + ' deg'
Message[4] := ' '
Message[5] := 'Min Distance = ' + MinDistance$'.1f' + ' mm'
Message[6] := 'Max Distance = ' + MaxDistance$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
*
* Part 2: Reconstruction of test objects and
* checking of the respective dimensions
*
* Inspection loop
NumScenes := 4
for SceneIndex := 1 to NumScenes by 1
dev_clear_window ()
dev_set_part (PartRow1, PartColumn1, PartRow2, PartColumn2)
* Reset the dispartities in the sheet of light model; all other settings can be reused
reset_sheet_of_light_model (SheetOfLightModelID)
*
* Create the test object by collecting the measured
* disparity profiles in a sheet-of-light model and
* transforming them to a 3D object model
gen_image_const (DisparityImageVis, 'uint2', DisparityProfileWidth, NumDisparityProfiles)
for Index := 0 to NumDisparityProfiles - 1 by 1
* Add the next disparity profile to the sheet of light model
read_image (ImageSearch, 'sheet_of_light/metal_part_' + (SceneIndex + 1) + '_disparity_line_' + Index$'03d')
set_profile_sheet_of_light (ImageSearch, SheetOfLightModelID, [])
* Accumulated profiles for visualization
get_grayval (ImageSearch, gen_tuple_const(DisparityProfileWidth,0), [0:DisparityProfileWidth - 1], Disparities)
set_grayval (DisparityImageVis, gen_tuple_const(DisparityProfileWidth,Index), [0:DisparityProfileWidth - 1], Disparities)
if (Index % 5 == 4 or Index == (NumDisparityProfiles - 1))
dev_display (DisparityImageVis)
Message := 'Disparity image of test object ' + SceneIndex
Message[1] := 'Adding disparity profile ' + (Index + 1) + '/' + NumDisparityProfiles
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
endif
endfor
* Get the 3D reconstruction of the test object and eliminate
* the background from the respective 3D object model
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)
*
* Align the intersection planes to the actual position and orientation
* of the test object and prepare the test object for the intersection
dev_clear_window ()
dev_set_part (PartRow1, PartColumn1, PartRow2, PartColumn2)
disp_object_model_3d (WindowHandle, Scene3D, VisualizationCamParam, VisualizationPose, [], [])
Message := 'Prepare the 3D object model of the test object'
Message[1] := ' - perform surface based matching for alignment'
Message[2] := ' - triangulate 3D object model'
disp_message (WindowHandle, Message[0], 'window', 12, 12, 'black', 'true')
*
* Match the test object with the reference sample.
* Note that the RelSamplingDistance has been set fairly small.
* This is necessary because the object has only little 3D variations
* that can be used by the matching process.
disp_message (WindowHandle, Message[0:1], 'window', 12, 12, 'black', 'true')
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)
* Triangulate the 3D object model
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')
*
* Calculate the intersections of the test object with the respectively
* aligned planes
intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane1AlignedPose, ObjectModel3DIntersection1)
intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane2AlignedPose, ObjectModel3DIntersection2)
intersect_plane_object_model_3d (Scene3DTest, IntersectionPlane3AlignedPose, ObjectModel3DIntersection3)
*
* Determine the intersections and convert them into XLD contours
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)
*
* Determine the actual dimensions by analysing the measurements
* from the test object
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)
*
* Visualize the object with the intersection planes and the respective
* intersections and measurement results
* Display headings
OverallCheckPassed := true
Message := 'Intersections with measurement lines'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,20})\\s','replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 310, 'black', 'true')
Message := 'Measurement results'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,20})\\s','replace_all'],'$1\n')
disp_message (WindowHandle, MessageWrapped, 'window', 12, 590, 'black', 'true')
* Display first intersection
affine_trans_contour_xld (Intersection1, Intersection1Vis, HomMat2DTranslate1)
affine_trans_contour_xld (FittedLines1, FittedLines1Vis, HomMat2DTranslate1)
dev_set_color (VisualizationColors[0])
dev_set_line_width (5)
dev_display (Intersection1Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines1Vis)
Message := 'Angle = ' + Angle1$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance1$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance1$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 310, 600, VisualizationColors[0], 'false')
ErrorIndicator := gen_tuple_const(3,'OK')
ErrorIndicatorColor := gen_tuple_const(3,'dim gray')
if (Angle1 [<] MinAngle or Angle1 [>] MaxAngle)
ErrorIndicator[0] := 'NOK'
ErrorIndicatorColor[0] := 'red'
OverallCheckPassed := false
endif
if (MinDistance1 [<] MinDistance)
ErrorIndicator[1] := 'NOK'
ErrorIndicatorColor[1] := 'red'
OverallCheckPassed := false
endif
if (MaxDistance1 [>] MaxDistance)
ErrorIndicator[2] := 'NOK'
ErrorIndicatorColor[2] := 'red'
OverallCheckPassed := false
endif
disp_message (WindowHandle, ErrorIndicator, 'window', 310, 880, ErrorIndicatorColor, 'false')
* Display second intersection
affine_trans_contour_xld (Intersection2, Intersection2Vis, HomMat2DTranslate2)
affine_trans_contour_xld (FittedLines2, FittedLines2Vis, HomMat2DTranslate2)
dev_set_color (VisualizationColors[1])
dev_set_line_width (5)
dev_display (Intersection2Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines2Vis)
Message := 'Angle = ' + Angle2$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance2$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance2$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 210, 600, VisualizationColors[1], 'false')
ErrorIndicator := gen_tuple_const(3,'OK')
ErrorIndicatorColor := gen_tuple_const(3,'dim gray')
if (Angle2 [<] MinAngle or Angle2 [>] MaxAngle)
ErrorIndicator[0] := 'NOK'
ErrorIndicatorColor[0] := 'red'
OverallCheckPassed := false
endif
if (MinDistance2 [<] MinDistance)
ErrorIndicator[1] := 'NOK'
ErrorIndicatorColor[1] := 'red'
OverallCheckPassed := false
endif
if (MaxDistance2 [>] MaxDistance)
ErrorIndicator[2] := 'NOK'
ErrorIndicatorColor[2] := 'red'
OverallCheckPassed := false
endif
disp_message (WindowHandle, ErrorIndicator, 'window', 210, 880, ErrorIndicatorColor, 'false')
* Display third intersection
affine_trans_contour_xld (Intersection3, Intersection3Vis, HomMat2DTranslate3)
affine_trans_contour_xld (FittedLines3, FittedLines3Vis, HomMat2DTranslate3)
dev_set_color (VisualizationColors[2])
dev_set_line_width (5)
dev_display (Intersection3Vis)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (FittedLines3Vis)
Message := 'Angle = ' + Angle3$'.1f' + ' deg'
Message[1] := 'Min Distance = ' + MinDistance3$'.1f' + ' mm'
Message[2] := 'Max Distance = ' + MaxDistance3$'.1f' + ' mm'
disp_message (WindowHandle, Message, 'window', 110, 600, VisualizationColors[2], 'false')
ErrorIndicator := gen_tuple_const(3,'OK')
ErrorIndicatorColor := gen_tuple_const(3,'dim gray')
if (Angle3 [<] MinAngle or Angle3 [>] MaxAngle)
ErrorIndicator[0] := 'NOK'
ErrorIndicatorColor[0] := 'red'
OverallCheckPassed := false
endif
if (MinDistance3 [<] MinDistance)
ErrorIndicator[1] := 'NOK'
ErrorIndicatorColor[1] := 'red'
OverallCheckPassed := false
endif
if (MaxDistance3 [>] MaxDistance)
ErrorIndicator[2] := 'NOK'
ErrorIndicatorColor[2] := 'red'
OverallCheckPassed := false
endif
disp_message (WindowHandle, ErrorIndicator, 'window', 110, 880, ErrorIndicatorColor, 'false')
* Display overall check result
if (OverallCheckPassed)
dev_set_color ('green')
gen_rectangle1 (Rectangle, 0, WindowWidth - 120, 80, WindowWidth)
dev_display (Rectangle)
disp_message (WindowHandle, 'OK', 'window', 30, 900, 'black', 'false')
else
dev_set_color ('red')
gen_rectangle1 (Rectangle, 0, WindowWidth - 120, 80, WindowWidth)
dev_display (Rectangle)
disp_message (WindowHandle, 'NOK', 'window', 30, 900, 'white', 'false')
endif
if (SceneIndex < NumScenes)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
逐句解释
NumDisparityProfiles := 441
定义变量NumDisparityProfiles,其值为441。
read_image (DisparityProfile, 'sheet_of_light/metal_part_1_disparity_line_000')
从文件'sheet_of_light/metal_part_1_disparity_line_000'中读取图像,并将其存储在变量DisparityProfile中。
create_sheet_of_light_model (DisparityProfile, 'calibration', 'offset_scale', SheetOfLightModelID)
使用函数create_sheet_of_light_model创建sheet of light模型,该模型基于视差图像DisparityProfile进行校准,并使用“offset_scale”方法进行缩放。SheetOfLightModelID是输出参数,存储所创建模型的ID。
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)
设置校准方法“offset_scale”的缩放因子,以便重建的三维物体模型大约以毫米为单位表示。这里设置了X轴的缩放因子为1,Y轴的缩放因子为4,Z轴的缩放因子为0.5。
MinZ := 220
定义一个变量MinZ,表示光板上的物体与背景分离的z坐标。
dev_update_off ()
set_system ('clip_region', 'false')
dev_close_window ()
关闭当前窗口并关闭更新显示。
get_image_size (DisparityProfile, DisparityProfileWidth, DisparityProfileHeight)
获取视差图像DisparityProfile的大小,并将其存储在变量DisparityProfileWidth和DisparityProfileHeight中。
WindowEnlargement := 350
WindowWidth := DisparityProfileWidth + WindowEnlargement
WindowHeight := NumDisparityProfiles
定义一个变量WindowEnlargement,表示窗口的宽度增量。然后根据视差图像和NumDisparityProfiles的大小确定窗口的宽度和高度。
dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle)
dev_set_part (0, 0, WindowHeight - 1, WindowWidth - 1)
get_part (WindowHandle, PartRow1, PartColumn1, PartRow2, PartColumn2)
打开一个新窗口并将其分割为一个矩形区域。然后获取该区域的位置和大小。
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw ('fill')
设置显示字体和绘图模式。
VisualizationPlaneSize := 150
gen_cam_par_area_scan_division (0.01, 0, 6e-6, 6e-6, WindowWidth / 2, WindowHeight / 2, WindowWidth, WindowHeight, VisualizationCamParam)
create_pose (-1550, 680, 5390, 122, 1, 357, 'Rp+T', 'gba', 'point', VisualizationPose)
VisualizationColors := ['magenta','blue','orange']
定义一些可视化参数,包括可视化平面大小、相机参数、姿态和颜色。