123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #pragma once
- #include <vector>
- #include <string>
- #include <math.h>
- #include <pcl\point_types.h>
- #include <pcl\point_cloud.h>
- #include "logger.h"
- namespace graft_cv {
- class CStemResult {
- public:
- CStemResult() :
- root_x(0.0),
- root_z(0.0),
- stem_size(0),
- batch_id(std::string("")),
- root_count(0)
- {};
- CStemResult(double x,double y, double z, int size, std::string& bid, int rcount)
- {
-
- root_x = x;
- root_y = y;
- root_z = z;
- stem_size = size;
- batch_id = std::string(bid);
- root_count = rcount;
- };
- double calcluate_distance(const CStemResult& sr) {
- double dist = 0.0;
- dist = sqrt((this->root_x - sr.root_x) *(this->root_x - sr.root_x) +
- //(this->root_y - sr.root_y) *(this->root_y - sr.root_y) +
- (this->root_z - sr.root_z) *(this->root_z - sr.root_z));
- return dist;
- };
- double root_x; //识别到的茎根x坐标
- double root_y;
- double root_z; //识别到的茎根z坐标
- int stem_size; //识别到的茎根矩形邻域点云数量
- std::string batch_id; //识别到的茎批次(每一次处理,批次一致)
- int root_count; //统计root的累计个数
- private:
- };
- class CStemResultInfos {
- public:
- CStemResultInfos(
- double seedling_dist,
- int holes_number,
- double x_min,
- double x_max,
- double z_min,
- double z_max,
- std::string pcd_id,
- CGcvLogger*pLog=0);
- ~CStemResultInfos();
-
- //void set_json_filename(std::string& filename);
- //void read_root_centers(std::string& filename);//读取历史数据,每次启动时,去取
- //void write_root_centers(std::string& filename);//保存当前数据,间隔一定时间保存一次
- void append(CStemResult& sr);
- void clear();
- void get_root_centers(std::vector<CStemResult>&rst);
- protected:
- CGcvLogger * m_pLogger;
- int m_max_size; //m_infos最大长度
- std::vector<CStemResult> m_infos;
- double m_seedling_dist; //植株间距,毫米
- std::vector<CStemResult> m_root_centers; //茎根位置历史平均值
- //int m_append_counter;
- //std::string m_json_filename;
- std::string m_pcdId;
- int m_holes_number;
- double m_xmin;
- double m_xmax;
- double m_zmin;
- double m_zmax;
- void _update_root_centers(CStemResult& sr); //通过当前的数据生成茎中心位置,聚类
- //void _filter_root_centers(double d1, double d2); //对生成的根中心m_root_centers进行过滤,剔除异常
- //void euclidean_clustering_ttsas(
- // pcl::PointCloud<pcl::PointXYZ>::Ptr in_cloud,
- // double d1, double d2,
- // std::vector<pcl::PointXYZ>&cluster_center,
- // std::vector<std::vector<int>> &clustr_member
- //);
- void gen_root_centers();
- };
- //植株状态,记录植株点云分布情况,用于确定植株是否被取走,穴位是否有苗
- class CSeedlingStatus {
- public:
- CSeedlingStatus(
- int dtype, //1-砧木, 0-穗苗
- double step, //x方向直方图点云分布,每个bin的宽度(默认5毫米)
- double x_min, //x的下限
- double x_max, //x的上限
- double pc_mean_dist, //点云,两点间平均距离
- CGcvLogger*pLog = 0);
- ~CSeedlingStatus();
- void set_x_centers(std::vector<double>&cx);
- void append_hist(std::vector<int>&xhist, //input
- std::vector<bool>&xstatus); //output
-
- protected:
- CGcvLogger * m_pLogger;
- int m_max_size; //最大记录长度
- int m_record_cursor;
- int m_global_cursor;
- cv::Mat m_history_histogram; //历史点云x方向分布直方图
- cv::Mat m_history_point_size; //历史点云框内数量
- cv::Mat m_history_status; //历史穴位是有苗状态
- std::vector<int> m_idx_low; //穴位对应的序号低位
- std::vector<int> m_idx_up; //穴位对应的序号低位
- int m_dtype; //1-砧木, 0-穗苗
- double m_xmin; //x的下限
- double m_xmax; //x的上限
- double m_bin_step; //x方向直方图点云分布,每个bin的宽度(默认5毫米)
- double m_pc_mean_dist; //点云,两点间平均距离
- std::vector<double>m_center_x;
- int m_hist_length;
- void get_status(std::vector<bool>&xstatus);
-
-
- };
- }
|