grab_occlusion.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <math.h>
  5. #include <pcl\point_types.h>
  6. #include <pcl\point_cloud.h>
  7. #include "logger.h"
  8. namespace graft_cv {
  9. class CStemResult {
  10. public:
  11. CStemResult() :
  12. root_x(0.0),
  13. root_z(0.0),
  14. stem_size(0),
  15. batch_id(std::string("")),
  16. root_count(0)
  17. {};
  18. CStemResult(double x,double y, double z, int size, std::string& bid, int rcount)
  19. {
  20. root_x = x;
  21. root_y = y;
  22. root_z = z;
  23. stem_size = size;
  24. batch_id = std::string(bid);
  25. root_count = rcount;
  26. };
  27. double calcluate_distance(const CStemResult& sr) {
  28. double dist = 0.0;
  29. dist = sqrt((this->root_x - sr.root_x) *(this->root_x - sr.root_x) +
  30. //(this->root_y - sr.root_y) *(this->root_y - sr.root_y) +
  31. (this->root_z - sr.root_z) *(this->root_z - sr.root_z));
  32. return dist;
  33. };
  34. double root_x; //识别到的茎根x坐标
  35. double root_y;
  36. double root_z; //识别到的茎根z坐标
  37. int stem_size; //识别到的茎根矩形邻域点云数量
  38. std::string batch_id; //识别到的茎批次(每一次处理,批次一致)
  39. int root_count; //统计root的累计个数
  40. private:
  41. };
  42. class CStemResultInfos {
  43. public:
  44. CStemResultInfos(
  45. double seedling_dist,
  46. int holes_number,
  47. double x_min,
  48. double x_max,
  49. double z_min,
  50. double z_max,
  51. std::string pcd_id,
  52. CGcvLogger*pLog=0);
  53. ~CStemResultInfos();
  54. //void set_json_filename(std::string& filename);
  55. //void read_root_centers(std::string& filename);//读取历史数据,每次启动时,去取
  56. //void write_root_centers(std::string& filename);//保存当前数据,间隔一定时间保存一次
  57. void append(CStemResult& sr);
  58. void clear();
  59. void get_root_centers(std::vector<CStemResult>&rst);
  60. protected:
  61. CGcvLogger * m_pLogger;
  62. int m_max_size; //m_infos最大长度
  63. std::vector<CStemResult> m_infos;
  64. double m_seedling_dist; //植株间距,毫米
  65. std::vector<CStemResult> m_root_centers; //茎根位置历史平均值
  66. //int m_append_counter;
  67. //std::string m_json_filename;
  68. std::string m_pcdId;
  69. int m_holes_number;
  70. double m_xmin;
  71. double m_xmax;
  72. double m_zmin;
  73. double m_zmax;
  74. void _update_root_centers(CStemResult& sr); //通过当前的数据生成茎中心位置,聚类
  75. //void _filter_root_centers(double d1, double d2); //对生成的根中心m_root_centers进行过滤,剔除异常
  76. //void euclidean_clustering_ttsas(
  77. // pcl::PointCloud<pcl::PointXYZ>::Ptr in_cloud,
  78. // double d1, double d2,
  79. // std::vector<pcl::PointXYZ>&cluster_center,
  80. // std::vector<std::vector<int>> &clustr_member
  81. //);
  82. void gen_root_centers();
  83. };
  84. }