Procházet zdrojové kódy

v0.1.15 优化切割位置识别精度: 初步识别点在目标内时用识别点;否则垂线方向搜索最近点作为切割点(适用于苗弯曲)

chenhongjiang před 1 rokem
rodič
revize
1046a8eb52
4 změnil soubory, kde provedl 36 přidání a 7 odebrání
  1. 1 0
      ReadMe.txt
  2. 1 1
      tcv_conf.yml
  3. 1 1
      tea_cv_api.cpp
  4. 33 5
      tea_sorter.cpp

+ 1 - 0
ReadMe.txt

@@ -13,3 +13,4 @@ v0.1.11 
 v0.1.12 优化抓取角度,提高效率,提高准确率
 v0.1.13 优化抓取角度;优化切割位置
 v0.1.14 优化抓取角度效率: thinning采用降采样再放大,提高效率;只做一次thinning,记录目标点坐标备用
+v0.1.15 优化切割位置识别精度: 初步识别点在目标内时用识别点;否则垂线方向搜索最近点作为切割点(适用于苗弯曲)

+ 1 - 1
tcv_conf.yml

@@ -17,7 +17,7 @@ conf_parameters:
    min_area_ratio_grab: 0.0
    max_area_ratio_grab: 0.1
    model_path_cut: "D:/projects/graft/py_code/retina_tea5/TeaDetector_cut_20231203001648.onnx"
-   object_threshold_cut: 4.4999998807907104e-01
+   object_threshold_cut: 0.8
    nms_threshold_cut: 5.0000000000000000e-01
    grid_row_cut: 1
    grid_col_cut: 1

+ 1 - 1
tea_cv_api.cpp

@@ -18,7 +18,7 @@ extern CRITICAL_SECTION g_cs;
 namespace graft_cv
 {
 
-	char *g_version_str = "0.1.14";
+	char *g_version_str = "0.1.15";
 
 	//configure
 	string g_conf_file = "./tcv_conf.yml";	

+ 33 - 5
tea_sorter.cpp

@@ -1000,13 +1000,15 @@ double CTeaSort::get_grab_position(
 
 /**
 * calc_bottom_vertex
-* 找到三角形两个底角点
+* 找到等腰三角形两个底角点
+*
+*       
 */
 void CTeaSort::calc_bottom_vertex(
 	cv::Point&vertex,	//input
-	double ref_angle,	//input, rad
-	double delta_angle, //input, rad
-	double radius,		//input
+	double ref_angle,	//input, rad, 等腰三角形高的方向
+	double delta_angle, //input, rad, 等腰三角形1/2分角
+	double radius,		//input, 等腰三角形腰长
 	cv::Point&bpt0,		//output
 	cv::Point&bpt1		//output
 ) 
@@ -1409,7 +1411,6 @@ void CTeaSort::calculate_stem_cut_position_opt(
 	
 	grab_x = grab_y = -1.0;
 	//crop image
-
 	cv::Point p3o(int(b.ppoint[4]), int(b.ppoint[5]));
 	cv::Point p4o(int(b.ppoint[6]), int(b.ppoint[7]));
 
@@ -1456,6 +1457,7 @@ void CTeaSort::calculate_stem_cut_position_opt(
 	cv::Mat bin_img;
 	double th = cv::threshold(gray_img, bin_img, 255, 255, cv::THRESH_OTSU);
 	cv::bitwise_not(bin_img, bin_img);
+	
 	if (m_cp.image_show) {
 		imshow_wait("cropped binary img", bin_img);
 	}
@@ -1471,6 +1473,32 @@ void CTeaSort::calculate_stem_cut_position_opt(
 	center_pt.x = 0.5*(p3.x + p4.x);
 	center_pt.y = 0.5*(p3.y + p4.y);
 
+	//检查center_pt附近,是否有目标,如果有就用center_pt点作为切割点
+	
+	int nnr = 7;
+	int cx, cy, knn, x, y;
+	cx = int(center_pt.x);
+	cy = int(center_pt.y);
+	knn = 0;
+	for (int r = -nnr; r <= nnr; ++r) {
+		y = r + cy;
+		if (y < 0 || y >= bin_img.rows) { continue; }
+		for (int c = -nnr; c <= nnr; ++c) {
+			x = cx + c;
+			if (x < 0 || x >= bin_img.cols) { continue; }
+			if (bin_img.at<unsigned char>(y, x) > 0) { knn++; }
+		}
+	}
+	if (knn > 0) {
+		grab_x = cx;
+		grab_y = cy;
+
+		grab_x += x1;
+		grab_y += y1;
+		return;
+	}
+	///////////////////////////////////////////////////////////////////////////////////////////////////////
+	//  否则通过骨架化图,找到旁边的点(适用于茎弯曲的情况)
 	int min_x, min_y;
 	double min_loss = 1.0e6;