Forráskód Böngészése

v0.7.9 修改接穗抓点靠上一点,增加了grab_offset,用来在找到茎节后的上下偏移得到抓取点,+值向上偏,-值向下偏

chenhongjiang 1 éve
szülő
commit
d17b0fb7f3
6 módosított fájl, 85 hozzáadás és 67 törlés
  1. 2 1
      ReadMe.txt
  2. 9 45
      config.cpp
  3. 2 0
      data_def_api.h
  4. 6 4
      gcv_conf.yml
  5. 65 16
      grab_point_rs.cpp
  6. 1 1
      graft_cv_api.cpp

+ 2 - 1
ReadMe.txt

@@ -93,4 +93,5 @@ v0.7.4 
 v0.7.5 优化叶片剔除功能(欧式距离聚类没能分割叶片和茎造成误剔除,本次采用ror方法剔除叶片,但有些耗时)
 v0.7.6 优化叶片剔除功能,修改ror,nb_point的数量系数,通过配置文件sc_grab_ror_ratio参数传入
 v0.7.7 优化茎判别问题:上下2片叶子,利用有效高度剔除;偏离z中心剔除,采用历史z均值
-v0.7.8 修改接穗抓点靠上一点
+v0.7.8 修改接穗抓点靠上一点
+v0.7.9 修改接穗抓点靠上一点,增加了grab_offset,用来在找到茎节后的上下偏移得到抓取点,+值向上偏,-值向下偏

+ 9 - 45
config.cpp

@@ -35,22 +35,7 @@ namespace graft_cv{
 			<< "oa_y_flip"<<  m_cparam->oa_y_flip 	
 			<< "oa_morph_radius"<<  m_cparam->oa_morph_radius 	
 			<< "oa_morph_iteration" << m_cparam->oa_morph_iteration
-			<< "oa_min_leaf_area"<< m_cparam->oa_min_leaf_area
-			/*<< "oa_min_hist_value"<< m_cparam->oa_min_hist_value
-			<< "oa_morph_radius_base"<<  m_cparam->oa_morph_radius_base	
-			<< "oa_morph_iteration_base" << m_cparam->oa_morph_iteration_base
-			<< "oa_min_hist_value_base"<< m_cparam->oa_min_hist_value_base
-
-			<< "oa_col_th_ratio"<< m_cparam->oa_col_th_ratio
-			<< "oa_row_th_ratio"<< m_cparam->oa_row_th_ratio
-			<< "oa_stem_x_padding"<< m_cparam->oa_stem_x_padding
-			<< "oa_stem_dia_min"<< m_cparam->oa_stem_dia_min
-			<< "oa_stem_fork_y_min"<< m_cparam->oa_stem_fork_y_min
-			<< "oa_stem_dia_mp"<< m_cparam->oa_stem_dia_mp
-
-			<< "oa_clip_y_min"<< m_cparam->oa_clip_y_min
-			<< "oa_clip_y_max"<<m_cparam->oa_clip_y_max*/
-
+			<< "oa_min_leaf_area"<< m_cparam->oa_min_leaf_area			
 
 			<< "rs_y_flip"<<  m_cparam->rs_y_flip 	
 			<< "rs_min_hist_value"<< m_cparam->rs_min_hist_value
@@ -106,6 +91,7 @@ namespace graft_cv{
 			<< "rs_grab_seedling_dist" << m_cparam->rs_grab_seedling_dist
 			<< "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
 
 			<< "sc_grab_xmin" << m_cparam->sc_grab_xmin
 			<< "sc_grab_xmax" << m_cparam->sc_grab_xmax
@@ -118,6 +104,7 @@ namespace graft_cv{
 			<< "sc_grab_seedling_dist" << m_cparam->sc_grab_seedling_dist
 			<< "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
 			<< "}"; 	
 	};
 	void CGCvConfig::read(const cv::FileNode& node){ //Read serialization for this class
@@ -140,20 +127,7 @@ namespace graft_cv{
 	    m_cparam->oa_morph_radius = (int)node["oa_morph_radius"];
 		m_cparam->oa_morph_iteration  = (int)node["oa_morph_iteration"];
 		m_cparam->oa_min_leaf_area = (int)node["oa_min_leaf_area"];
-		/*m_cparam->oa_min_hist_value = (int)node["oa_min_hist_value"];
-		m_cparam->oa_morph_radius_base = (int)node["oa_morph_radius_base"];
-		m_cparam->oa_morph_iteration_base  = (int)node["oa_morph_iteration_base"];
-		m_cparam->oa_min_hist_value_base = (int)node["oa_min_hist_value_base"];
-
-		m_cparam->oa_col_th_ratio = (double)node["oa_col_th_ratio"];
-		m_cparam->oa_row_th_ratio  = (double)node["oa_row_th_ratio"];
-		m_cparam->oa_stem_x_padding = (int)node["oa_stem_x_padding"];
-		m_cparam->oa_stem_dia_min = (int)node["oa_stem_dia_min"];
-		m_cparam->oa_stem_fork_y_min  = (int)node["oa_stem_fork_y_min"];
-		m_cparam->oa_stem_dia_mp = (double)node["oa_stem_dia_mp"];
-		m_cparam->oa_clip_y_min = (int)node["oa_clip_y_min"];
-		m_cparam->oa_clip_y_max = (int)node["oa_clip_y_max"];*/
-
+		
 		m_cparam->rs_y_flip = (bool)(int)node["rs_y_flip"];
 		m_cparam->rs_col_th_ratio  = (double)node["rs_col_th_ratio"];
 		m_cparam->rs_row_th_ratio  = (double)node["rs_row_th_ratio"];
@@ -207,6 +181,7 @@ namespace graft_cv{
 		m_cparam->rs_grab_seedling_dist = (double)node["rs_grab_seedling_dist"];
 		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->sc_grab_xmin = (double)node["sc_grab_xmin"];
 		m_cparam->sc_grab_xmax = (double)node["sc_grab_xmax"];
@@ -219,6 +194,7 @@ namespace graft_cv{
 		m_cparam->sc_grab_seedling_dist = (double)node["sc_grab_seedling_dist"];
         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"];
   }
 	string get_cparam_info(ConfigParam*m_cparam)
 	{
@@ -242,21 +218,7 @@ namespace graft_cv{
 			<< "oa_y_flip:\t"<<  m_cparam->oa_y_flip 	 << endl
 			<< "oa_morph_radius:\t"<<  m_cparam->oa_morph_radius 	 << endl
 			<< "oa_morph_iteration:\t" << m_cparam->oa_morph_iteration << endl
-			<< "oa_min_leaf_area:\t"<< m_cparam->oa_min_leaf_area << endl
-			/*<< "oa_min_hist_value:\t"<< m_cparam->oa_min_hist_value<<endl
-			<< "oa_morph_radius_base:\t"<<  m_cparam->oa_morph_radius_base	 << endl
-			<< "oa_morph_iteration_base:\t" << m_cparam->oa_morph_iteration_base << endl
-			<< "oa_min_hist_value_base:\t"<< m_cparam->oa_min_hist_value_base << endl
-
-			<< "oa_col_th_ratio:\t"<< m_cparam->oa_col_th_ratio << endl
-			<< "oa_row_th_ratio:\t"<< m_cparam->oa_row_th_ratio << endl
-			<< "oa_stem_x_padding:\t"<< m_cparam->oa_stem_x_padding << endl
-			<< "oa_stem_dia_min:\t"<< m_cparam->oa_stem_dia_min << endl
-			<< "oa_stem_fork_y_min:\t"<< m_cparam->oa_stem_fork_y_min << endl
-			<< "oa_stem_dia_mp:\t"<< m_cparam->oa_stem_dia_mp << endl
-
-			<< "oa_clip_y_min:\t"<< m_cparam->oa_clip_y_min << endl
-			<< "oa_clip_y_max:\t"<<m_cparam->oa_clip_y_max << endl*/
+			<< "oa_min_leaf_area:\t"<< m_cparam->oa_min_leaf_area << endl		
 
 
 			<< "rs_y_flip:\t"<<  m_cparam->rs_y_flip 	 << endl
@@ -313,6 +275,7 @@ namespace graft_cv{
             << "rs_grab_seedling_dist:\t" << m_cparam->rs_grab_seedling_dist << endl
 			<< "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
 
 
 			<< "sc_grab_xmin:\t" << m_cparam->sc_grab_xmin << endl
@@ -326,6 +289,7 @@ namespace graft_cv{
 			<< "sc_grab_seedling_dist:\t" << m_cparam->sc_grab_seedling_dist << endl
 			<< "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
 			<< "}" << endl; 	
 		return buff.str();
 	}

+ 2 - 0
data_def_api.h

@@ -116,6 +116,7 @@ typedef struct{
 	double rs_grab_seedling_dist;
 	int rs_grab_stem_min_pts;
 	double rs_grab_ror_ratio;
+	double rs_grab_offset;
 
 	// scion grab based points cloud
 	double sc_grab_xmin;
@@ -130,6 +131,7 @@ typedef struct{
 	double sc_grab_seedling_dist;
 	int sc_grab_stem_min_pts;
 	double sc_grab_ror_ratio;
+	double sc_grab_offset;
 
 
 

+ 6 - 4
gcv_conf.yml

@@ -1,6 +1,6 @@
 %YAML:1.0
 conf_parameters:
-   image_show: 0
+   image_show: 1
    image_return: 1
    image_row_grid: 20
    image_col_grid: 100
@@ -65,7 +65,7 @@ conf_parameters:
    rs_oa_pixel_ratio: 2.3333300000000001e-001
    rs_cut_pixel_ratio: 5.8479999999999997e-002
    sc_cut_pixel_ratio: 8.7499999999999994e-002
-   rs_grab_xmin: -200
+   rs_grab_xmin: -50
    rs_grab_xmax: 200
    rs_grab_ymin: -45
    rs_grab_ymax: 0
@@ -76,10 +76,11 @@ conf_parameters:
    rs_grab_seedling_dist: 40.0
    rs_grab_stem_min_pts: 50
    rs_grab_ror_ratio: 0.8
-   sc_grab_xmin: -200
+   rs_grab_offset: -5.0
+   sc_grab_xmin: -50
    sc_grab_xmax: 200
    sc_grab_ymin: -45
-   sc_grab_ymax: 0
+   sc_grab_ymax: 45
    sc_grab_zmin: 300
    sc_grab_zmax: 400
    sc_grab_stem_diameter: 5.0
@@ -87,5 +88,6 @@ conf_parameters:
    sc_grab_seedling_dist: 40.0
    sc_grab_stem_min_pts: 45
    sc_grab_ror_ratio: 0.8
+   sc_grab_offset: -5.0
    
 

+ 65 - 16
grab_point_rs.cpp

@@ -97,15 +97,42 @@ namespace graft_cv {
 				m_pLogger->ERRORINFO(m_pcdId + ": no valid input");
 				return (-1);
 			}
-		}	
-
-		
+		}			
 
 		if (m_ppImgSaver && *m_ppImgSaver) {
 			(*m_ppImgSaver)->saveBinPly(m_raw_cloud, m_pcdId);
 		}
 		if (m_cparam.image_show) {
-			viewer_cloud(m_raw_cloud, m_pcdId + std::string(": raw point cloud"));
+			pcl::visualization::PCLVisualizer viewer(m_pcdId + std::string(": raw point cloud"));
+			viewer.addCoordinateSystem();
+			viewer.addPointCloud<pcl::PointXYZ>(m_raw_cloud, "raw_cloud");
+			viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 1, 1, "raw_cloud");
+			viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "raw_cloud");
+
+			float xmin, ymin, zmin, xmax, ymax, zmax;
+			xmin = m_cparam.rs_grab_xmin;
+			ymin = m_cparam.rs_grab_ymin; 
+			zmin = m_cparam.rs_grab_zmin; 
+			xmax = m_cparam.rs_grab_xmax; 
+			ymax = m_cparam.rs_grab_ymax; 
+			zmax = m_cparam.rs_grab_zmax;
+			if (m_dtype == 0) {
+				xmin = m_cparam.sc_grab_xmin;
+				ymin = m_cparam.sc_grab_ymin;
+				zmin = m_cparam.sc_grab_zmin;
+				xmax = m_cparam.sc_grab_xmax;
+				ymax = m_cparam.sc_grab_ymax;
+				zmax = m_cparam.sc_grab_zmax;
+			}
+
+			viewer.addCube(xmin, xmax,ymin, ymax,  zmin, zmax, 0.75, 0.0, 0.0, "AABB_");
+			viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION,
+				pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME, "AABB_");
+
+			while (!viewer.wasStopped()) {
+				viewer.spinOnce(100);
+				boost::this_thread::sleep(boost::posix_time::microseconds(100000));
+			}
 		}
 		return rst;
 	}
@@ -2274,7 +2301,7 @@ void CRootStockGrabPoint::line_filter(
 	)
 	{
 		valid_line_index.clear();
-		float th_ratio = 1.0;		//原始点云和直线点云邻域尺寸增加原来的20%,不能当做抓取点
+		float th_ratio = 2.5;		//原始点云和直线点云邻域尺寸增加原来的20%,不能当做抓取点
 		pt_idx = -1;
 
 		float ymin, ymax;
@@ -2333,8 +2360,7 @@ void CRootStockGrabPoint::line_filter(
 				}
 				else {
 					stem_width.push_back(dz);
-				}
-				
+				}				
 			}
 			else {
 				stem_width.push_back(0);
@@ -2345,7 +2371,11 @@ void CRootStockGrabPoint::line_filter(
 			cy += 1.0;
 		}
 		std::vector<float>valid_stem_width;
-		for (auto&w : stem_width) { valid_stem_width.push_back(w); }
+		for (auto&w : stem_width) {
+			if (w > 0) {
+				valid_stem_width.push_back(w);
+			}
+		}
 		float mu = get_hist_mean(valid_stem_width);
 		float stdv = get_hist_std(valid_stem_width, mu);
 
@@ -2354,22 +2384,33 @@ void CRootStockGrabPoint::line_filter(
 		float th = mu + th_ratio * stdv;
 		if(m_dtype == 0){
 			//穗苗尽量找高点
-			if(max_pos>15){
-				if (th < max_val) {
+			if (th < max_val) {
 				int i = max_pos-10;
-				for (; i < max_pos; ++i) {
+				if (i < 0) { i = 0; }
+				for (; i < stem_width.size(); ++i) {
 					if (stem_width.at(i) >= th) {
 						break;
 					}
 				}
 				max_pos = i;
 			}
+			else {
+				//从上往下10mm
+				int i = stem_width.size() - 10;
+				for (; i >=0; --i) {
+					if (stem_width.at(i) >= mu) {
+						break;
+					}
+				}
+				max_pos = i;
 			}
+			max_pos += static_cast<int>(m_cparam.rs_grab_offset);			
 		}
 		else{
 			//砧木可以按低点
-			if (th < max_val) {
-				int i = 0;
+			if (th < max_val) {				
+				int i = max_pos - 10;
+				if (i < 0) { i = 0; }
 				for (; i < stem_width.size(); ++i) {
 					if (stem_width.at(i) >= th) {
 						break;
@@ -2377,7 +2418,10 @@ void CRootStockGrabPoint::line_filter(
 				}
 				max_pos = i;
 			}
+			max_pos += static_cast<int>(m_cparam.rs_grab_offset);
 		}
+		if (max_pos < 0) { max_pos = 0;	}
+		if (max_pos >= online_points.size()) { max_pos = online_points.size() - 1; }
 
 		/////////////////////////////////////////////////////////////////////
 		//直线点云,获取指定区域的dx_line,dz_line
@@ -2389,9 +2433,14 @@ void CRootStockGrabPoint::line_filter(
 		box_filter_line.setMin(Eigen::Vector4f(cx - rx*radius, cy - 2, cz - rz*radius, 1));
 		box_filter_line.setMax(Eigen::Vector4f(cx + rx*radius, cy + 2, cz + rz*radius, 1));
 		box_filter_line.filter(*cloud_inbox_line);
-		pcl::getMinMax3D(*cloud_inbox_line, min_point, max_point);
-		float z_mu = 0.5 * (max_point(2) + min_point(2));
-		float x_mu = 0.5 * (max_point(0) + min_point(0));
+
+  		float z_mu = cz;
+		float x_mu = cx;
+		if (cloud_inbox_line->points.size() > 5) {
+			pcl::getMinMax3D(*cloud_inbox_line, min_point, max_point);
+			z_mu = 0.5 * (max_point(2) + min_point(2));
+			x_mu = 0.5 * (max_point(0) + min_point(0));
+		}
 
 		pt.x = x_mu;
 		pt.y = cy;

+ 1 - 1
graft_cv_api.cpp

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