当前位置:   article > 正文

Halcon tiff 点云读取以及平面矫正_halcon 点云平面校准

halcon 点云平面校准

一、读取tiff 图

  1. dev_close_window ()
  2. dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
  3. xResolution:=0.0025
  4. yResolution:=0.0025
  5. zResolution:=0.001
  6. read_image (IntputImage, 'C:/Users/alber/Desktop/2023-08-15_16-38-24-982_/Sta5_002.tif')
  7. zoom_image_factor (IntputImage, IntputImage, 1,4, 'constant')
  8. get_domain (IntputImage, Domain)
  9. *获取该区域的最大最小值
  10. min_max_gray (Domain, IntputImage, 0, Min, Max, Range)
  11. *去除无效数据
  12. threshold (IntputImage, Region,-1.2, Max)
  13. reduce_domain (IntputImage, Region, ImageReduced)
  14. get_image_size (ImageReduced, Width, Height)
  15. convert_image_type (ImageReduced, ImageConvertedX, 'real')
  16. *生成xy坐标的图像映射,乘以分辨率就是xy的相对值
  17. gen_image_surface_first_order (ImageSurface, 'real', 1, 0, 0, 0, 0, Width, Height)
  18. gen_image_surface_first_order (ImageSurface1, 'real', 0, 1, 0, 0, 0, Width, Height)
  19. scale_image (ImageSurface, X, xResolution, 0)
  20. scale_image (ImageSurface1, Y, yResolution, 0)
  21. *创建3D模型
  22. xyz_to_object_model_3d (Y,X,ImageReduced, ObjectModel3D)
  23. write_object_model_3d (ObjectModel3D, 'ply', 'C:/Users/alber/Desktop/abc.ply', [], [])
  24. disp_object_model_3d (WindowHandle, [ObjectModel3D], [], [], ['color_0','alpha'], ['green',0.7])

二、平面矫正

用Z轴来矫正

  1. select_points_object_model_3d (ObjectModel3D, 'point_coord_x', 2.73, 3.2, ObjectModel3DThresholded)
  2. select_points_object_model_3d (ObjectModel3DThresholded, 'point_coord_y', 1, 3.4, ObjectModel3DThresholded)
  3. fit_primitives_object_model_3d (ObjectModel3DThresholded, ['primitive_type','fitting_algorithm'], ['plane','least_squares_tukey'], ObjectModel3DOut)
  4. * 这一步很重要
  5. get_object_model_3d_params (ObjectModel3DOut, 'primitive_parameter_pose', pose)
  6. *用Z轴来矫正
  7. * 将旋转的角度转转回去
  8. pose[3]:=-pose[3]
  9. pose[4]:=-pose[4]
  10. pose[5]:=-pose[5]
  11. write_object_model_3d (ObjectModel3DThresholded, 'ply', 'C:/Users/alber/Desktop/abc3333.ply', [], [])
  12. *
  13. rigid_trans_object_model_3d (ObjectModel3DThresholded, pose, ObjectModel3DRigidTrans)
  14. write_object_model_3d (ObjectModel3DRigidTrans, 'ply', 'C:/Users/alber/Desktop/abc3333afffff.ply', [], [])
  15. rigid_trans_object_model_3d (ObjectModel3D, pose, ObjectModel3DRigidProdUCE)
  16. write_object_model_3d (ObjectModel3DRigidProdUCE, 'ply', 'C:/Users/alber/Desktop/ABC_CR.ply', [], [])

三、 从一个姿态转到指定的姿态

1、将原始姿态pose ->matrix1

2、将指定的姿态pose 2->matrix2

3、svd  矩阵分解,计算出两个姿态的差接矩阵M

4、矩阵-》pose

5、rigid_trans_object_model_3d

矫正前:

矫正后:

 

  1. dev_close_window ()
  2. dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
  3. xResolution:=0.0025
  4. yResolution:=0.0025
  5. zResolution:=0.001
  6. read_image (IntputImage, 'C:/Users/alber/Desktop/2023-08-15_16-38-24-982_/Sta5_002.tif')
  7. zoom_image_factor (IntputImage, IntputImage, 1,4, 'constant')
  8. get_domain (IntputImage, Domain)
  9. *获取该区域的最大最小值
  10. min_max_gray (Domain, IntputImage, 0, Min, Max, Range)
  11. *去除无效数据
  12. threshold (IntputImage, Region,-1.2, Max)
  13. reduce_domain (IntputImage, Region, ImageReduced)
  14. get_image_size (ImageReduced, Width, Height)
  15. convert_image_type (ImageReduced, ImageConvertedX, 'real')
  16. *生成xy坐标的图像映射,乘以分辨率就是xy的相对值
  17. gen_image_surface_first_order (ImageSurface, 'real', 1, 0, 0, 0, 0, Width, Height)
  18. gen_image_surface_first_order (ImageSurface1, 'real', 0, 1, 0, 0, 0, Width, Height)
  19. scale_image (ImageSurface, X, xResolution, 0)
  20. scale_image (ImageSurface1, Y, yResolution, 0)
  21. *创建3D模型
  22. xyz_to_object_model_3d (Y,X,ImageReduced, ObjectModel3D)
  23. write_object_model_3d (ObjectModel3D, 'ply', 'C:/Users/alber/Desktop/abc.ply', [], [])
  24. disp_object_model_3d (WindowHandle, [ObjectModel3D], [], [], ['color_0','alpha'], ['green',0.7])
  25. select_points_object_model_3d (ObjectModel3D, 'point_coord_x', 2.73, 3.2, ObjectModel3DThresholded)
  26. select_points_object_model_3d (ObjectModel3DThresholded, 'point_coord_y', 1, 3.4, ObjectModel3DThresholded)
  27. fit_primitives_object_model_3d (ObjectModel3DThresholded, ['primitive_type','fitting_algorithm'], ['plane','least_squares_tukey'], ObjectModel3DOut)
  28. * 这一步很重要
  29. get_object_model_3d_params (ObjectModel3DOut, 'primitive_parameter_pose', pose)
  30. *用Z轴来矫正
  31. * 将旋转的角度转转回去
  32. pose[3]:=-pose[3]
  33. pose[4]:=-pose[4]
  34. pose[5]:=-pose[5]
  35. write_object_model_3d (ObjectModel3DThresholded, 'ply', 'C:/Users/alber/Desktop/abc3333.ply', [], [])
  36. *
  37. rigid_trans_object_model_3d (ObjectModel3DThresholded, pose, ObjectModel3DRigidTrans)
  38. write_object_model_3d (ObjectModel3DRigidTrans, 'ply', 'C:/Users/alber/Desktop/abc3333afffff.ply', [], [])
  39. rigid_trans_object_model_3d (ObjectModel3D, pose, ObjectModel3DRigidProdUCE)
  40. write_object_model_3d (ObjectModel3DRigidProdUCE, 'ply', 'C:/Users/alber/Desktop/ABC_CR.ply', [], [])
  41. select_points_object_model_3d (ObjectModel3DRigidProdUCE, 'point_coord_y', 3.5, 3.501, ObjectModel3DThresholded1)
  42. object_model_3d_to_xyz (X1, Y1, Z, ObjectModel3DRigidProdUCE, 'from_xyz_map', pose, pose)
  43. * 画出roi
  44. gen_region_line (ROI_0, 1125.4, 1025.4, 1125.4, 1081.84)
  45. get_region_points (ROI_0, Rows, Columns)
  46. get_grayval (Z, Rows, Columns, Grayval)
  47. xr:=Columns*0.0025
  48. yr:=Rows*0.0025
  49. * 不能拟合直线
  50. gen_object_model_3d_from_points(xr, yr, Grayval, ObjectModel3D2)
  51. fit_primitives_object_model_3d (ObjectModel3D2, 'primitive_type', 'all', ObjectModel3DOut1)
  52. get_object_model_3d_params (ObjectModel3DOut1, 'num_lines', GenParamValue)
  53. Grayval:=Grayval+10
  54. gen_contour_polygon_xld (Contour, xr, Grayval)
  55. fit_line_contour_xld (Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
  56. *第二段
  57. gen_region_line (ROI_1, 1125.4, 1338.49, 1125.4, 1412.09)
  58. get_region_points (ROI_1, Rows1, Columns1)
  59. get_grayval (Z, Rows1, Columns1, Grayval1)
  60. Grayval1:=Grayval1+10
  61. xr1:=Columns1*0.0025
  62. yr1:=Rows1*0.0025
  63. gen_contour_polygon_xld (Contour2, xr1, Grayval1)
  64. fit_line_contour_xld (Contour2, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr1, Nc1, Dist1)
  65. gen_contour_polygon_xld (Contour2, xr, Grayval)
  66. * 计算两条直线的交点
  67. intersection_lines ( RowBegin, ColBegin, RowEnd, ColEnd, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Row, Column, IsOverlapping)

三、将点云生成Z Y Z图

object_model_3d_to_xyz (X1, Y1, Z, ObjectModel3DRigidProdUCE, 'from_xyz_map', pose, pose)

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

闽ICP备14008679号