HOLCON源码学习

阅读: 评论:0

HOLCON源码学习

HOLCON源码学习

真是日了狗了,兜兜转转又来到了图像识别

*  
*
* Part 1
*
* Create a sheet-of-light model to collect the profiles
* and set the scaling factors for the reconstruction.
* Note, that through the scalings, only approximate
* 3d coordinates are obtained (scaling does not
* replace calibration).
* Fortunately, in this case, this is completely sufficient
* for the task, as we only want to compare the parts
* qualitatively.
*
* Create sheet-of-light model with following parameters
NumProfiles := 441
DisparityRange := 512
ProfileWidth := 626
* In this example, the profiles are not measured by HALCON.
* Instead, they are obtained directly from the sheet-of-light
* sensor. Nevertheless the profile width is defined
* within create_sheet_of_light_model by the width of a rectangle.
get_system ('clip_region', ClipRegion)
set_system ('clip_region', 'false')
gen_rectangle1 (Rectangle, 0, 0, DisparityRange - 1, ProfileWidth - 1)
set_system ('clip_region', ClipRegion)
create_sheet_of_light_model (Rectangle, 'calibration', 'offset_scale', SheetOfLightModelID)
* Set the scaling factors such that the distance
* of neighboring 3D points is approximately the same
* as in the real object.
ScaleX := 2
ScaleY := 8
ScaleZ := 1
Clip := 435
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)
*
* Init display
dev_update_off ()
dev_close_window ()
dev_open_window_fit_size (0, 0, ProfileWidth, NumProfiles, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*
* Create an image to display the disparities
gen_image_const (Image, 'uint2', ProfileWidth, NumProfiles)
*
* Create the reference object by collecting
* the measured profiles in a sheet-of-light model
*
for Index := 0 to NumProfiles - 1 by 1* Add the next profile to the sheet of light modelread_image (ImageModel, 'sheet_of_light/metal_part_1_disparity_line_' + Index$'03d')set_profile_sheet_of_light (ImageModel, SheetOfLightModelID, [])* Visualize accumulated profilesget_grayval (ImageModel, gen_tuple_const(ProfileWidth,0), [0:ProfileWidth - 1], Grayval)set_grayval (Image, gen_tuple_const(ProfileWidth,Index), [0:ProfileWidth - 1], Grayval)if (Index % 5 == 0)dev_display (Image)endifMessage := 'Measure reference object'Message[1] := 'Add profile ' + (Index + 1) + '/' + NumProfilesdisp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
endfor
*
Message := 'Prepare the model for distance measurement ...'
disp_message (WindowHandle, Message, 'window', 60, 12, 'black', 'true')
Status := ' ... triangulate object ...'
Status[1] := ' ... subsample object ...'
Status[2] := ' ... create surface model for alignment ...'
* Select the relevant part from the scene
get_sheet_of_light_result_object_model_3d (SheetOfLightModelID, Model3DAll)
select_points_object_model_3d (Model3DAll, 'point_coord_z', Clip, 800, Model3D)
* Clean up memory
clear_object_model_3d (Model3DAll)
*
* Prepare reference object for a more robust
* surface comparison.
*
* To get a more robust result, the reference object is
* subsampled to achieve a better resolution for the
* measurement. The subsampling needs a triangulation
* as a preprocessing step.
*
* Triangulate the model in a simple way
disp_message (WindowHandle, Status[0], 'window', 100, 12, 'white', 'false')
surface_normals_object_model_3d (Model3D, 'mls', 'mls_force_inwards', 'true', ObjectModel3DNormals)
triangulate_object_model_3d (ObjectModel3DNormals, 'greedy', 'greedy_remove_small_surfaces', 200, TriangulatedObjectModel3D, Information)
* Clean up memory
clear_object_model_3d (ObjectModel3DNormals)
* Sample the object for distance measurements
disp_message (WindowHandle, [Status[0] + ' ready.',Status[1]], 'window', 100, 12, 'white', 'false')
max_diameter_object_model_3d (TriangulatedObjectModel3D, Diameter)
sample_object_model_3d (TriangulatedObjectModel3D, 'fast', Diameter * 0.002, [], [], Model3DSampled)
disp_message (WindowHandle, [Status[0:1] + ' ready.',Status[2]], 'window', 100, 12, 'white', 'false')
* Clean up memory
clear_object_model_3d (Model3D)
*
* Create a surface model for alignment
create_surface_model (TriangulatedObjectModel3D, 0.01, 'model_invert_normals', 'true', SurfaceModelID)
* Display status
Message := Message + ' ready.'
disp_message (WindowHandle, Status + ' ready.', 'window', 100, 12, 'white', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Display reference model
dev_clear_window ()
create_pose (1100, 1300, 35000, 140, 350, 55, 'Rp+T', 'gba', 'point', PoseDisplay)
Title := 'Reference object (uncalibrated measurement)'
Instructions[0] := 'Rotate: Left button'
Instructions[1] := 'Zoom:   Shift + left button'
Instructions[2] := 'Move:   Ctrl  + left button'
visualize_object_model_3d (WindowHandle, TriangulatedObjectModel3D, [], PoseDisplay, [], [], Title, [], Instructions, PoseOut)
*
* Main loop
*
* Perform a surface comparison on a number of objects
*
NumScenes := 4
for SceneIndex := 1 to NumScenes by 1* Reset the dispartities in the sheet of light model. All other settings can be reusedreset_sheet_of_light_model (SheetOfLightModelID)* Collect and display the disparities from the sensorgen_image_const (Image, 'uint2', ProfileWidth, NumProfiles)for Index := 0 to NumProfiles - 1 by 1read_image (ImageSearch, 'sheet_of_light/metal_part_' + (SceneIndex + 1) + '_disparity_line_' + Index$'03d')get_grayval (ImageSearch, gen_tuple_const(ProfileWidth,0), [0:ProfileWidth - 1], Grayval)set_grayval (Image, gen_tuple_const(ProfileWidth,Index), [0:ProfileWidth - 1], Grayval)if (Index % 5 == 0)dev_display (Image)endifMessage := 'Measure scene ' + SceneIndex + '/' + NumScenesMessage[1] := 'Add profile ' + (Index + 1) + '/' + NumProfilesdisp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')* Add the next profile to the sheet-of-light model* The offset is considered constant (= ScaleY)set_profile_sheet_of_light (ImageSearch, SheetOfLightModelID, [])endfor* Select the relevant part from the sceneget_sheet_of_light_result_object_model_3d (SheetOfLightModelID, Scene3DAll)select_points_object_model_3d (Scene3DAll, 'point_coord_z', Clip, 800, Scene3D)* Clean up memoryclear_object_model_3d (Scene3DAll)* Match the two objects* 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, 'Match model and scene ...', 'window', 60, 12, 'black', 'true')find_surface_model (SurfaceModelID, Scene3D, 0.02, 0.2, 0, 'false', [], [], Pose, Score, NotUsed)pose_invert (Pose, PosesInvert)* Transform the scene to match the reference objectrigid_trans_object_model_3d (Scene3D, PosesInvert, ObjectModel3DRigidTrans)* Measure the distances between the scene and the modeldistance_object_model_3d (ObjectModel3DRigidTrans, Model3DSampled, [], 0.0, 'signed_distances', 'true')* Select points with a high distance below the model (negative distance)* and the points above the model (positive distance)select_points_object_model_3d (ObjectModel3DRigidTrans, '&distance', -1000, -ScaleY * 1.5, ObjectModel3DThresholdedUp)select_points_object_model_3d (ObjectModel3DRigidTrans, '&distance', ScaleY * 1.5, 1000, ObjectModel3DThresholdedDown)* Calculate connected components of the points below (negative distance) and* the connected components of the points above (positive distance) the model.* The distance threshold should be greater than the distance between* two scan lines (> ScaleY)connection_object_model_3d (ObjectModel3DThresholdedUp, 'distance_3d', ScaleY + 5, ObjectModel3DConnectedUp)connection_object_model_3d (ObjectModel3DThresholdedDown, 'distance_3d', ScaleY + 5, ObjectModel3DConnectedDown)* Keep the large components, discard small ones as noiseselect_object_model_3d (ObjectModel3DConnectedUp, 'num_points', 'and', 200, 1000000, ObjectModel3DSelectedUp)select_object_model_3d (ObjectModel3DConnectedDown, 'num_points', 'and', 200, 1000000, ObjectModel3DSelectedDown)* Set the visualization parameters and values depending on the* position of the error points.NumErrors := |ObjectModel3DSelectedDown| + |ObjectModel3DSelectedUp|Title := 'Found ' + NumErrors + ' error(s)'ErrorColorUp := 'magenta'ErrorColorDown := 'red'ErrorColorNames := 'color_' + [2:NumErrors + 1]VisParamNames := ['point_size','point_size_1','color_0','color_1',ErrorColorNames,'alpha_' + NumErrors,'disp_background']VisParamValues := [5.0,2.0,'white','green',gen_tuple_const(|ObjectModel3DSelectedUp|,ErrorColorUp),gen_tuple_const(|ObjectModel3DSelectedDown|,ErrorColorDown),0.8,'true']* Display the errorneous regionsdev_clear_window ()disp_message (WindowHandle, ['Bent up','Bent down'], 'window', 12, 500, [ErrorColorUp,ErrorColorDown], 'false')visualize_object_model_3d (WindowHandle, [TriangulatedObjectModel3D,ObjectModel3DRigidTrans,ObjectModel3DSelectedUp,ObjectModel3DSelectedDown], [], PoseDisplay, VisParamNames, VisParamValues, Title, ['','','#' + [1:NumErrors]], Instructions, PoseOut1)* Clean up memoryclear_object_model_3d ([Scene3D,ObjectModel3DConnectedUp,ObjectModel3DConnectedDown,ObjectModel3DSelectedUp,ObjectModel3DSelectedDown,ObjectModel3DRigidTrans,ObjectModel3DThresholdedUp,ObjectModel3DThresholdedDown])
endfor
* Clean up memory
clear_object_model_3d ([Model3DSampled,TriangulatedObjectModel3D])
clear_sheet_of_light_model (SheetOfLightModelID)
clear_surface_model (SurfaceModelID)


本文发布于:2024-02-05 04:02:35,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170723624362897.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:show me the code
标签:源码   HOLCON
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23