浏览代码

v0.7.18 优化茎节位置识别,评估方法改为顶点高度和中值高度差,增加阈值控制是否有效

chenhongjiang 1 年之前
父节点
当前提交
a1973de562
共有 7 个文件被更改,包括 43 次插入14 次删除
  1. 2 1
      ReadMe.txt
  2. 6 1
      config.cpp
  3. 2 1
      data_def_api.h
  4. 3 1
      gcv_conf.yml
  5. 7 4
      grab_point_rs.cpp
  6. 1 1
      graft_cv_api.cpp
  7. 22 5
      peak_finder.cpp

+ 2 - 1
ReadMe.txt

@@ -102,4 +102,5 @@ v0.7.13 
 v0.7.14 增加指定抓取位置的功能,抓取位置在ymax向下指定距离为抓取位置
 v0.7.15 优化茎节位置识别
 v0.7.16 优化茎节位置识别,增加平均茎节高度约束,10mm范围
-v0.7.17 优化茎节位置识别,不存在显著茎节的用平均茎节高度替代,否则用识别到的茎节位置
+v0.7.17 优化茎节位置识别,不存在显著茎节的用平均茎节高度替代,否则用识别到的茎节位置
+v0.7.18 优化茎节位置识别,评估方法改为顶点高度和中值高度差,增加阈值控制是否有效

+ 6 - 1
config.cpp

@@ -92,6 +92,7 @@ namespace graft_cv{
 			<< "rs_grab_stem_min_pts" << m_cparam->rs_grab_stem_min_pts
 			<< "rs_grab_ror_ratio" << m_cparam->rs_grab_ror_ratio
 			<< "rs_grab_offset" << m_cparam->rs_grab_offset
+			<< "rs_grab_fork_th" << m_cparam->rs_grab_fork_th
 
 			<< "sc_grab_xmin" << m_cparam->sc_grab_xmin
 			<< "sc_grab_xmax" << m_cparam->sc_grab_xmax
@@ -105,6 +106,7 @@ namespace graft_cv{
 			<< "sc_grab_stem_min_pts" << m_cparam->sc_grab_stem_min_pts
 			<< "sc_grab_ror_ratio" << m_cparam->sc_grab_ror_ratio
 			<< "sc_grab_offset" << m_cparam->sc_grab_offset
+			<< "sc_grab_fork_th" << m_cparam->sc_grab_fork_th
 			<< "}"; 	
 	};
 	void CGCvConfig::read(const cv::FileNode& node){ //Read serialization for this class
@@ -182,6 +184,7 @@ namespace graft_cv{
 		m_cparam->rs_grab_stem_min_pts = (int)node["rs_grab_stem_min_pts"];
 		m_cparam->rs_grab_ror_ratio = (double)node["rs_grab_ror_ratio"];
 		m_cparam->rs_grab_offset = (double)node["rs_grab_offset"];
+		m_cparam->rs_grab_fork_th = (double)node["rs_grab_fork_th"];
 
 		m_cparam->sc_grab_xmin = (double)node["sc_grab_xmin"];
 		m_cparam->sc_grab_xmax = (double)node["sc_grab_xmax"];
@@ -195,6 +198,7 @@ namespace graft_cv{
         m_cparam->sc_grab_stem_min_pts = (int)node["sc_grab_stem_min_pts"];
 		m_cparam->sc_grab_ror_ratio = (double)node["sc_grab_ror_ratio"];
 		m_cparam->sc_grab_offset = (double)node["sc_grab_offset"];
+		m_cparam->sc_grab_fork_th = (double)node["sc_grab_fork_th"];
   }
 	string get_cparam_info(ConfigParam*m_cparam)
 	{
@@ -276,7 +280,7 @@ namespace graft_cv{
 			<< "rs_grab_stem_min_pts:\t" << m_cparam->rs_grab_stem_min_pts << endl
 			<< "rs_grab_ror_ratio:\t" << m_cparam->rs_grab_ror_ratio << endl
 			<< "rs_grab_offset:\t" << m_cparam->rs_grab_offset << endl
-
+			<< "rs_grab_fork_th:\t" << m_cparam->rs_grab_fork_th << endl			
 
 			<< "sc_grab_xmin:\t" << m_cparam->sc_grab_xmin << endl
 			<< "sc_grab_xmax:\t" << m_cparam->sc_grab_xmax << endl
@@ -290,6 +294,7 @@ namespace graft_cv{
 			<< "sc_grab_stem_min_pts:\t" << m_cparam->sc_grab_stem_min_pts << endl
 			<< "sc_grab_ror_ratio:\t" << m_cparam->sc_grab_ror_ratio << endl
 			<< "sc_grab_offset:\t" << m_cparam->sc_grab_offset << endl
+			<< "sc_grab_fork_th:\t" << m_cparam->sc_grab_fork_th << endl
 			<< "}" << endl; 	
 		return buff.str();
 	}

+ 2 - 1
data_def_api.h

@@ -117,6 +117,7 @@ typedef struct{
 	int rs_grab_stem_min_pts;
 	double rs_grab_ror_ratio;
 	double rs_grab_offset;
+	double rs_grab_fork_th;
 
 	// scion grab based points cloud
 	double sc_grab_xmin;
@@ -132,7 +133,7 @@ typedef struct{
 	int sc_grab_stem_min_pts;
 	double sc_grab_ror_ratio;
 	double sc_grab_offset;
-
+	double sc_grab_fork_th;
 
 
 } ConfigParam;

+ 3 - 1
gcv_conf.yml

@@ -90,6 +90,7 @@ conf_parameters:
    rs_grab_stem_min_pts: 50
    rs_grab_ror_ratio: 0.85
    rs_grab_offset: 0
+   rs_grab_fork_th: 0.7
 
 
    sc_grab_xmin: -200
@@ -98,7 +99,7 @@ conf_parameters:
    sc_grab_ymax: 10
    sc_grab_zmin: 300
    sc_grab_zmax: 400
-   #sc_grab_xmin: -30
+   #sc_grab_xmin: -30 
    #sc_grab_xmax: 170
    #sc_grab_ymin: -10
    #sc_grab_ymax: 100
@@ -110,5 +111,6 @@ conf_parameters:
    sc_grab_stem_min_pts: 45
    sc_grab_ror_ratio: 0.85
    sc_grab_offset: 0
+   sc_grab_fork_th: 0.7
    
 

+ 7 - 4
grab_point_rs.cpp

@@ -2457,8 +2457,11 @@ void CRootStockGrabPoint::line_filter(
 			max_pos = tmp_max_pos;
 			max_pos_ref = max_pos;			
 		}
-		//±£´æÀúÊ·¾¥½ÚλÖÃ		
-		if (max_power > 0.5) {
+		//±£´æÀúÊ·¾¥½ÚλÖÃ
+		float max_power_th = m_cparam.rs_grab_fork_th;
+		if (m_dtype == 0) { max_power_th = m_cparam.sc_grab_fork_th; }
+
+		if (max_power > max_power_th) {
 			m_stem_fork_ys.insert(m_stem_fork_ys.begin(), max_pos);
 			if (m_stem_fork_ys.size() > m_stem_fork_ys_size) { m_stem_fork_ys.pop_back(); }
 			
@@ -2471,7 +2474,7 @@ void CRootStockGrabPoint::line_filter(
 		//float max_val = stem_width.at(max_pos);
 		//float th = mu + th_ratio * stdv;
 		if(m_dtype == 0){			
-			if (max_power > 0.5) {
+			if (max_power > max_power_th) {
 				max_pos_ref = max_pos;
 				max_pos += static_cast<int>(m_cparam.sc_grab_offset);
 			}
@@ -2487,7 +2490,7 @@ void CRootStockGrabPoint::line_filter(
 			}			
 		}
 		else{			
-			if (max_power > 0.5) {
+			if (max_power > max_power_th) {
 				max_pos_ref = max_pos;
 				max_pos += static_cast<int>(m_cparam.rs_grab_offset);
 			}

+ 1 - 1
graft_cv_api.cpp

@@ -20,7 +20,7 @@ extern CRITICAL_SECTION g_cs;
 namespace graft_cv
 {
 
-	char *g_version_str = "0.7.17";
+	char *g_version_str = "0.7.18";
 
 	//configure
 	string g_conf_file = "./gcv_conf.yml";	

+ 22 - 5
peak_finder.cpp

@@ -261,9 +261,9 @@ namespace graft_cv {
 		float mu,
 		std::vector<float>& peak_power)
 	{
-		int radius = 5;
+		int radius = 10;
 		for (int& pos : peak_indices) {
-			float left_min, right_min;
+			/*float left_min, right_min;
 			left_min = right_min = stem_width.at(pos);
 			for (int i = pos - radius; i < pos; ++i) {
 				if (i < 0) { continue; }
@@ -277,9 +277,26 @@ namespace graft_cv {
 			}
 			left_min = 0.5 * (right_min + left_min);
 			float h = stem_width.at(pos) - left_min;
-			float r = 1.0 - fabs(left_min - mu) / mu;
-			float power = h*r;
-			peak_power.push_back(power);
+			float r = 1.0 -fabs(left_min - mu) / mu;
+			float power = h*r;*/
+			std::vector<float>tmp;
+			for (int i = pos - radius; i < pos + radius; ++i) {
+				if (i < 0) { continue; }
+				if (i >= stem_width.size()) { break; }
+				if (stem_width.at(i) == 0) { continue; }
+				tmp.push_back(stem_width.at(i));
+			}
+			//median
+			if (tmp.size() > 0) {
+				std::sort(tmp.begin(), tmp.end());
+				float median = tmp.at(int(tmp.size() / 2.0));
+				float power = stem_width.at(pos) - median;
+				peak_power.push_back(power);
+			}
+			else {
+				peak_power.push_back(0.0);
+			}
+			
 		}
 	}
 }