point_tool.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // Created by zx on 2021/5/11.
  3. //
  4. #ifndef ROBOT_CONTROL_FEATURE_EXTRA_SRC_POINT_TOOL_HPP_
  5. #define ROBOT_CONTROL_FEATURE_EXTRA_SRC_POINT_TOOL_HPP_
  6. #include <iostream>
  7. #include <pcl/point_types.h>
  8. #include <pcl/point_cloud.h>
  9. #include <pcl/io/pcd_io.h>
  10. #include <pcl/segmentation/sac_segmentation.h>
  11. #include <pcl/ModelCoefficients.h>
  12. #include <pcl/filters/extract_indices.h>
  13. #include <pcl/segmentation/extract_clusters.h>
  14. #include <pcl/common/transforms.h>
  15. #include <opencv2/opencv.hpp>
  16. #include "static_tool.hpp"
  17. //bool string2point(std::string str, pcl::PointXYZ &point);
  18. //pcl::PointCloud<pcl::PointXYZ>::Ptr ReadTxtCloud(std::string file);
  19. void save_cloud_txt(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, std::string file);
  20. void save_cloud_txt(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud, std::string file);
  21. //double distance(cv::Point2f p1, cv::Point2f p2);
  22. bool isRect(std::vector<cv::Point2f> &points);
  23. std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> segmentation(pcl::PointCloud<pcl::PointXYZ>::Ptr sor_cloud);
  24. void rpy_to_rotation_matrix();
  25. void rotation_matrix_to_rpy();
  26. void reverse_test();
  27. bool read_pointcloud(std::string filename, pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud);
  28. class pclTool {
  29. public:
  30. static pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> ComplementSymmetryPoints(pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> &in) {
  31. pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> out(new pcl::PointCloud<pcl::PointXYZ>);
  32. ComplementSymmetryPoints(in, out);
  33. return out;
  34. }
  35. static void ComplementSymmetryPoints(pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> &in, pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> &out) {
  36. cv::Point2f centroid;
  37. float radius;
  38. std::vector<cv::Point2f> cv_in;
  39. for (auto &point:in->points) {
  40. cv_in.emplace_back(point.x, point.y);
  41. }
  42. cv::minEnclosingCircle(cv_in, centroid, radius);
  43. pcl::copyPointCloud(*in, *out);
  44. for (auto &point: in->points) {
  45. out->emplace_back(SymmetryPoint(point, centroid));
  46. }
  47. }
  48. static pcl::PointXYZ SymmetryPoint(pcl::PointXYZ &in, cv::Point2f &centroid) {
  49. pcl::PointXYZ sp;
  50. sp.x = 2 * centroid.x - in.x;
  51. sp.y = 2 * centroid.y - in.y;
  52. sp.z = in.z;
  53. return sp;
  54. }
  55. };
  56. #endif //ROBOT_CONTROL_FEATURE_EXTRA_SRC_POINT_TOOL_HPP_