当前位置:   article > 正文

halcon matlab 中pose matrix之间的转换_halcon pose

halcon pose

 pose_to_hom_mat3d (TransPose, HomMat3D)

 原理:

 matlab 验证:

  1. function [a,b]=getMatrix(pose)
  2. syms x y z;
  3. x=deg2rad(pose(4));
  4. y=deg2rad(pose(5));
  5. z=deg2rad(pose(6));
  6. mat_x=[1 0 0 0;0 cos(x) -sin(x) 0;0 sin(x) cos(x) 0; 0 0 0 1];
  7. mat_y=[cos(y) 0 sin(y) 0;0 1 0 0;-sin(y) 0 cos(y) 0;0 0 0 1];
  8. mat_z=[cos(z) -sin(z) 0 0;sin(z) cos(z) 0 0;0 0 1 0;0 0 0 1];
  9. % 最常用的集中方式
  10. if pose(7)==0
  11. a=mat_x*mat_y*mat_z;
  12. elseif pose(7)==1
  13. a=mat_z*mat_y*mat_x;
  14. elseif pose(7)==2
  15. a=mat_z*mat_x*mat_y;
  16. end
  17. M_t=[1 0 0 pose(1);
  18. 0 1 0 pose(2);
  19. 0 0 1 pose(3);
  20. 0 0 0 1];
  21. b=M_t*a;
  22. end

pcl: 

  1. //
  2. int pose_to_hom_mat3d(vector<double>&pose,Eigen::Matrix4d &matarix)
  3. {
  4. if (pose.size()!=7)
  5. {
  6. return -1;
  7. }
  8. // 转换为弧度
  9. double roll_arc = pose[3] * M_PI/180.0;
  10. double pitch_arc = pose[4] * M_PI / 180.0;
  11. double yaw_arc = pose[5] * M_PI / 180.0;
  12. // 初始化欧拉角
  13. Eigen::Vector3d euler_angle(roll_arc, pitch_arc, yaw_arc);
  14. // 使用eigen库,欧拉角转旋转矩阵
  15. Eigen::AngleAxisd x_rollAngle (euler_angle[0], Eigen::Vector3d::UnitX()); // x
  16. Eigen::AngleAxisd Y_yawAngle(euler_angle[1], Eigen::Vector3d::UnitY()); // y
  17. Eigen::AngleAxisd z_pitchAngle(euler_angle[2], Eigen::Vector3d::UnitZ()); //z
  18. Eigen::Matrix3d q = Eigen::Matrix3d::Zero();
  19. if (pose[6]==0) // xyz
  20. {
  21. q = x_rollAngle*Y_yawAngle*z_pitchAngle;
  22. }
  23. else if (pose[6] == 1) // zxy
  24. {
  25. q = z_pitchAngle *x_rollAngle* Y_yawAngle ;
  26. }
  27. else if (pose[6] == 2) // zyx
  28. {
  29. q = z_pitchAngle * Y_yawAngle * x_rollAngle;
  30. }
  31. else if (pose[6] == 3) // xzy
  32. {
  33. q = x_rollAngle*z_pitchAngle * Y_yawAngle ;
  34. }
  35. Eigen::Matrix4d Tranlate_Matrix = Eigen::Matrix4d::Zero();
  36. Eigen::Matrix4d R_Matrix = Eigen::Matrix4d::Zero();
  37. Tranlate_Matrix(0, 0) = 1.0;
  38. Tranlate_Matrix(1, 1) = 1.0;
  39. Tranlate_Matrix(2, 2) = 1.0;
  40. Tranlate_Matrix(0,3) = pose[0];
  41. Tranlate_Matrix(1, 3) = pose[1];
  42. Tranlate_Matrix(2, 3) = pose[2];
  43. Tranlate_Matrix(3, 3) = 1.0;
  44. for (size_t i = 0; i < 3; i++)
  45. {
  46. for (size_t j = 0; j < 3; j++)
  47. {
  48. R_Matrix(i, j) = q(i,j);
  49. }
  50. }
  51. R_Matrix(3,3) = 1.0;
  52. matarix = Tranlate_Matrix*R_Matrix;
  53. cout << "\matarix =\n" << matarix << endl << endl;
  54. return 0;
  55. }

对比:

 

 

pose_compose

  1. * pose1->m1 pose2->m2
  2. * PoseCompose=m1*m2
  3. pose_compose (pose1, TransPose, PoseCompose)

matlab

  1. clear;
  2. pose1=[0.0 0.0 1.0 0.0 90.0 0.0 0];
  3. poseTrans=[1.0 2.5 2.0 90.0 20.0 0.0 0];
  4. [~,b]=getMatrix(pose1);
  5. [~,b2]=getMatrix(poseTrans);
  6. mat=b*b2

rigid_trans_object_model_3d

halcon 案例代码:

  1. * This example program shows how to use the operator
  2. * rigid_trans_object_model_3d in HALCON. In this example
  3. * a cylinder is created. In a second step, the cylinder is
  4. * tranformed with a rigid transformation. The generated
  5. * primitves of the 3D object models are visualized.
  6. *
  7. * Initialize program
  8. dev_close_window ()
  9. dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
  10. set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
  11. gen_cam_par_area_scan_division (0.016, 0, 5e-6, 5e-6, 320, 240, 640, 480, CamParam)
  12. create_pose (-1, 1, 20, 110, 0, 270, 'Rp+T', 'gba', 'point', DisplayPose)
  13. create_pose (1, 2.5, 2, 90, 20, 0, 'Rp+T', 'gba', 'point', TransPose)
  14. *
  15. * Create a cylinder without transformation
  16. gen_cylinder_object_model_3d ([0,0,1,0,90,0,0], 0.5, 0, 2, ObjectModel3DCylinder)
  17. get_object_model_3d_params (ObjectModel3DCylinder, 'primitive_pose', pose1)
  18. disp_object_model_3d_safe (WindowHandle, ObjectModel3DCylinder, CamParam, DisplayPose, 'disp_pose', 'true')
  19. disp_message (WindowHandle, 'Cylinder before transformation', 'window', 12, 12, 'black', 'true')
  20. disp_continue_message (WindowHandle, 'black', 'true')
  21. stop ()
  22. *
  23. * Apply a rigid transformation
  24. * 姿态和矩阵之间的想换转换
  25. pose_to_hom_mat3d (pose1, HomMat3D)
  26. pose_to_hom_mat3d (TransPose, HomMat3D2)
  27. * 计算两个pose 之间的乘法
  28. * pose1->m1 pose2->m2
  29. * PoseCompose=m1*m2
  30. pose_compose (pose1, TransPose, PoseCompose)
  31. pose_to_hom_mat3d (PoseCompose, HomMat3DPosecompose)
  32. ***
  33. rigid_trans_object_model_3d (ObjectModel3DCylinder, TransPose, ObjectModel3DRigidTrans)
  34. get_object_model_3d_params (ObjectModel3DRigidTrans, 'primitive_pose', pose2)
  35. pose_to_hom_mat3d (pose2, HomMat3D24)
  36. dev_clear_window ()
  37. disp_object_model_3d_safe (WindowHandle, ObjectModel3DRigidTrans, CamParam, pose2, 'disp_pose', 'true')
  38. disp_message (WindowHandle, 'Cylinder after transformation', 'window', 12, 12, 'black', 'true')
  39. stop ()

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

闽ICP备14008679号