point3D_tool.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // Created by huli on 2021/3/24.
  3. //
  4. #ifndef NNXX_TESTS_POINT3D_TOOL_H
  5. #define NNXX_TESTS_POINT3D_TOOL_H
  6. #include <pcl/point_cloud.h>
  7. #include <pcl/point_types.h>
  8. #include <vector>
  9. #include <opencv4/opencv2/opencv.hpp>
  10. #include "log/log.h"
  11. class Point3D_tool
  12. {
  13. public:
  14. static bool WriteTxtCloud(const std::string &file, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud);
  15. static bool WriteTxtCloud(const std::string &file, pcl::PointCloud<pcl::PointXYZI>::Ptr &cloud);
  16. static bool ReadTxtCloud(const std::string &file, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud);
  17. template <typename PclPoint>
  18. static int getMinRect(cv::RotatedRect &rect, pcl::shared_ptr<pcl::PointCloud<PclPoint>> &clouds);
  19. // template <typename PclPoint>
  20. // static int getMinRect(cv::RotatedRect &rect, pcl::shared_ptr<pcl::PointCloud<PclPoint>> &points) {
  21. static int getRectCloud(cv::RotatedRect &rect, pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> &points, float z_value = 0, int numbers = 100);
  22. template <typename PclPoint>
  23. static int getRectCloud(pcl::shared_ptr<pcl::PointCloud<PclPoint>> &clouds, pcl::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> &points, float z_value = 0, int numbers = 100);
  24. static void getRectWidthlength(cv::RotatedRect &rect, double &width, double &length);
  25. private:
  26. static bool string2PointXYZ(const std::string &str, pcl::PointXYZ &point) {
  27. std::istringstream iss;
  28. iss.str(str);
  29. float value;
  30. float data[3];
  31. for (int i = 0; i < 3; ++i) {
  32. if (iss >> value) {
  33. data[i] = value;
  34. } else {
  35. return false;
  36. }
  37. }
  38. point.x = data[0];
  39. point.y = data[1];
  40. point.z = data[2];
  41. return true;
  42. }
  43. };
  44. #endif //NNXX_TESTS_POINT3D_TOOL_H