cut_point_rs.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //cut point recognization for rootstock plant
  2. #pragma once
  3. #include <time.h>
  4. #include <opencv.hpp>
  5. #include "data_def_api.h"
  6. #include "data_def.h"
  7. #include "logger.h"
  8. #include "imstorage_manager.h"
  9. using namespace cv;
  10. namespace graft_cv{
  11. class CRootStockCutPoint{
  12. public:
  13. CRootStockCutPoint(ConfigParam&c,CGcvLogger*pLog=0);
  14. ~CRootStockCutPoint();
  15. int up_point_detect(//上切割点,切前识别
  16. ImgInfo*,
  17. Mat&,
  18. PositionInfo& posinfo
  19. );
  20. //int up_point_reid( // 上切割点,切后重识别
  21. // ImgInfo*,
  22. // Mat&,
  23. // double edge_length,
  24. // PositionInfo& posinfo
  25. // );
  26. void set_image_saver(CImStoreManager** ppis){m_ppImgSaver=ppis;}
  27. private:
  28. Mat m_binImg;// binary image
  29. Mat m_grayImg;// gray image
  30. Mat m_edgeImg;
  31. string m_imgId;
  32. CImStoreManager** m_ppImgSaver;
  33. //返回图片,用于调试
  34. ImgInfo* m_pImginfoBinFork;//fork-y, right-x
  35. ImgInfo* m_pImgCorners;//corners, reference-point, candidate box
  36. ImgInfo* m_pImgCutPoint;//reference-point, cutpoint
  37. //global configure parameters
  38. ConfigParam& m_cparam;
  39. CGcvLogger * m_pLogger;
  40. // image segment
  41. void img_segment(Mat&);
  42. // get_optimal_corner()
  43. // return 0--success, 1--error
  44. int get_optimal_corner(
  45. int ref_x,
  46. int ref_y,
  47. std::vector<Point2f>& corners,
  48. int stem_dia,
  49. double cand_corner_box_width_ratio,
  50. double cand_corner_box_xoffset_ratio,
  51. double opt_corner_xoffset_ratio,
  52. double opt_corner_yoffset_ratio,
  53. double corner_mask_radius_ratio,
  54. Point2f& cut_pt);
  55. void get_default_cutpoint(
  56. int fork_cent_x,
  57. int fork_cent_y,
  58. int fork_stem_dia,
  59. Point2f& cut_pt);
  60. void clear_imginfo();
  61. /// pre-cut calculationo
  62. //# 通过砧木切前切割点识别结果(切割点)、二值图像,茎根y值,刀角度
  63. //# 输出切割点到根部的边缘曲线长度
  64. double get_cut_edge_length(
  65. Mat& bin_img,
  66. Mat& edge_img,
  67. gcv_point<int>& start_pt, //up cut point
  68. gcv_point<int>& lower_cut_pt,//output
  69. gcv_point<int>& root_pt,//output
  70. double cut_angle,
  71. int y_max,
  72. int stem_dia,
  73. clock_t t0
  74. );
  75. void find_lower_cut_point(
  76. Mat& bin_img,
  77. gcv_point<int>&start_pt,
  78. gcv_point<int>&end_pt,//output
  79. double cut_angle,
  80. int stem_dia);
  81. double calculate_edge_length(
  82. Mat& edge_img,
  83. gcv_point<int>&lower_cut_pt,
  84. gcv_point<int>&root_pt,//output
  85. int y_max,
  86. clock_t t0
  87. );
  88. //corner evluation
  89. void corner_magnificence(
  90. const vector<Point2f>& cand_pts,
  91. int stem_dia,
  92. double corner_mask_radius_ratio,
  93. vector<double>& scores
  94. );
  95. //functions for reid
  96. int get_root_point_reid(
  97. int x0,
  98. int x1,
  99. int stem_end_y,
  100. bool is_right //是否右侧根部点, true-右侧,false-左侧
  101. );
  102. void find_upper_cut_point_reid(
  103. Mat& edge_img,
  104. gcv_point<int>&start_pt,
  105. gcv_point<int>&end_pt,//output
  106. double curve_length
  107. );
  108. void get_stem_root_y(
  109. vector<int>&hist_row,
  110. double rs_stem_dia_min,
  111. int &stem_end_y);
  112. };
  113. };