当前位置:   article > 正文

HALCON的基础运用案例:- 例1- 3D点云的分割_halcon经典例子

halcon经典例子

前言:

在这个例子里面展示了用HALCON的操作函数segment_object_model_3d,来把一个输入的2.5D的3D图像进行分割。这里因为图像是一组圆柱体,有运用了一个物体的判别操作函数:dev_display_fitting_results。然后,自动给出了region的划分。


程序说明:

步骤1:读取2.5D的数据:

read_image (XYZ, '3d_machine_vision/segmentation/3d_primitives_xyz_01.tif')

数据就是几个圆柱体:

步骤2,转化为3D数据

  1. access_channel (XYZ, X, 1)
  2. access_channel (XYZ, Y, 2)
  3. access_channel (XYZ, Z, 3)

【案】这时候,应该是拿了X,Y,Z三个坐标视图数据:【Franlin案,2.5D也许就是理解为通过三视图来转化得到的3D图像?感觉又不是,因为X,Y,Z的轮廓几乎是一样的角度】我们看给出的变量图如下:

X,Y,Z几乎为一样的角度,【案】也许是双目视图。

如果看X,Y的3D视图:都是一个平面

 当然Z是三维图形

步骤3:准备分割:

  1. xyz_to_object_model_3d (X, Y, Z, ObjectModel3DID)
  2. prepare_object_model_3d (ObjectModel3DID, 'segmentation', 'false', 'max_area_holes', 100)

这里先通过xyz_to_object_model_3d【具体,参考我的其他博客说明】,把刚才原始的2.5D的图像,搞成了一个3D点云模型ObjectModel3DID:然后在prepare_object_model_3d【依据设定准备处理的内存等】里面设定好分割的参数准备和设定。

步骤4:开始分割:

  1. ParSegmentation := ['max_orientation_diff','max_curvature_diff','output_xyz_mapping','min_area']
  2. ValSegmentation := [0.13,0.11,'true',150]
  3. ParFitting := ['primitive_type','fitting_algorithm']
  4. ValFitting := ['all','least_squares_huber']
  5. * Segmentation and fitting is done in one step,
  6. * because the parameter 'fitting' is set to 'true' by default
  7. segment_object_model_3d (ObjectModel3DID, [ParSegmentation,ParFitting], [ValSegmentation,ValFitting], ObjectModel3DOutID)

 输入,输出的模型数据比较如下:

 每一栏都是一个分割后的3D实体:

然后,Primitive Tpye应该为基本的3D模型,【大概,因为不同的角度,有不同的识别类型】

步骤5,显示分割的模型:

步骤6,运用fitting:


案例源码:

  1. * ***********************************************************************
  2. * This example program shows how to use the operator
  3. * segment_object_model_3d in HALCON. First, the 2.5D
  4. * input image is segmented. Additionally, with the same
  5. * operator, a fitting is performed. The result of the
  6. * 3D segmentation is converted to a region and is
  7. * displayed. Finally, the values of the fitted radii
  8. * for the cylinders and spheres are visualized.
  9. * ***********************************************************************
  10. dev_update_off ()
  11. dev_close_window ()
  12. * Input: 2.5D image
  13. read_image (XYZ, '3d_machine_vision/segmentation/3d_primitives_xyz_01.tif')
  14. dev_open_window_fit_image (XYZ, 0, 0, -1, -1, WindowHandle)
  15. set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
  16. * Access to (x-, y-, z-)coordinates
  17. access_channel (XYZ, X, 1)
  18. access_channel (XYZ, Y, 2)
  19. access_channel (XYZ, Z, 3)
  20. *
  21. Message := 'Generate a 3D object model from an'
  22. Message[1] := 'XYZ image and segment primitives'
  23. Message[2] := '(spheres, cylinders, planes) in it:'
  24. dev_display (Z)
  25. disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
  26. disp_continue_message (WindowHandle, 'black', 'true')
  27. stop ()
  28. * Prepare the segmentation
  29. xyz_to_object_model_3d (X, Y, Z, ObjectModel3DID)
  30. prepare_object_model_3d (ObjectModel3DID, 'segmentation', 'false', 'max_area_holes', 100)
  31. ParSegmentation := ['max_orientation_diff','max_curvature_diff','output_xyz_mapping','min_area']
  32. ValSegmentation := [0.13,0.11,'true',150]
  33. ParFitting := ['primitive_type','fitting_algorithm']
  34. ValFitting := ['all','least_squares_huber']
  35. * Segmentation and fitting is done in one step,
  36. * because the parameter 'fitting' is set to 'true' by default
  37. segment_object_model_3d (ObjectModel3DID, [ParSegmentation,ParFitting], [ValSegmentation,ValFitting], ObjectModel3DOutID)
  38. * Show the result of the segmentation
  39. dev_set_colored (12)
  40. for Index := 0 to |ObjectModel3DOutID| - 1 by 1
  41. object_model_3d_to_xyz (XTmp, YTmp, ZTmp, ObjectModel3DOutID[Index], 'from_xyz_map', [], [])
  42. get_domain (ZTmp, DomainTmp)
  43. if (Index == 0)
  44. copy_obj (DomainTmp, Domain, 1, 1)
  45. else
  46. concat_obj (Domain, DomainTmp, Domain)
  47. endif
  48. endfor
  49. dev_display (Domain)
  50. disp_message (WindowHandle, '3D Segmentation', 'window', 12, 12, 'black', 'true')
  51. disp_message (WindowHandle, 'Segmented objects: ' + |ObjectModel3DOutID|, 'window', 40, 12, 'black', 'true')
  52. disp_continue_message (WindowHandle, 'black', 'true')
  53. stop ()
  54. * Show the result of the fitting
  55. dev_clear_window ()
  56. dev_display_fitting_results (RegionCylinder, RegionSphere, RegionPlane, RegionNone, ObjectModel3DOutID, WindowHandle, [])
  57. *
  58. * Example code, if further inspections should be made:
  59. *
  60. * Store only the data of the primitive to save memory
  61. for Index := 0 to |ObjectModel3DOutID| - 1 by 1
  62. * Copy only the data of the primitive
  63. copy_object_model_3d (ObjectModel3DOutID[Index], 'primitives_all', CopiedObjectModel3DID)
  64. * Further inspections
  65. * .....
  66. * .....
  67. endfor
  68. dev_update_on ()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/109037
推荐阅读
相关标签
  

闽ICP备14008679号