Przeglądaj źródła

v0.1.22 切割模型标注关键点更改,2、3点分别是第一、二叶子分叉点

chenhongjiang 1 rok temu
rodzic
commit
e1b38232fc
4 zmienionych plików z 22 dodań i 18 usunięć
  1. 2 1
      ReadMe.txt
  2. 1 1
      tcv_conf.yml
  3. 1 1
      tea_cv_api.cpp
  4. 18 15
      tea_sorter.cpp

+ 2 - 1
ReadMe.txt

@@ -19,4 +19,5 @@ v0.1.17 抓取
 v0.1.18 抓取旋转180度设置,0-不旋转,非0-旋转180
 v0.1.19 抓取旋转180度设置, 标定
 v0.1.20 切割位置识别min_x未定义就使用bug修改
-v0.1.21 切割图片是彩色图,app提供的通道顺序是rgb,改成opencv用的bgr
+v0.1.21 切割图片是彩色图,app提供的通道顺序是rgb,改成opencv用的bgr
+v0.1.22 切割模型标注关键点更改,2、3点分别是第一、二叶子分叉点

+ 1 - 1
tcv_conf.yml

@@ -17,7 +17,7 @@ conf_parameters:
    min_area_ratio_grab: 0.0
    max_area_ratio_grab: 0.1
    rot_degree_grab: 0
-   model_path_cut: "D:/projects/graft/py_code/retina_tea5/TeaDetector_cut_20231203001648.onnx"
+   model_path_cut: "D:/projects/graft/py_code/retina_tea5/TeaDetector_cut_20231219003541.onnx"
    object_threshold_cut: 0.8
    nms_threshold_cut: 0.1
    grid_row_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.21";
+	char *g_version_str = "0.1.22";
 
 	//configure
 	string g_conf_file = "./tcv_conf.yml";	

+ 18 - 15
tea_sorter.cpp

@@ -324,10 +324,10 @@ int CTeaSort::detect(
 			}
 			//cut points
 			if (m_dtype == img_type::tea_cut) {	
-				//lines, p3-p4
+				//lines, p2-p3
 				cv::line(img_rst,
-					cv::Point(int(b.ppoint[4]), int(b.ppoint[5])),
-					cv::Point(int(b.ppoint[6]), int(b.ppoint[7])),					
+					cv::Point(int(b.ppoint[2]), int(b.ppoint[3])),
+					cv::Point(int(b.ppoint[4]), int(b.ppoint[5])),					
 					cv::Scalar(0, 215, 255), 2);
 				//line x
 				int cx = int(b.operate_point[0]);
@@ -403,7 +403,9 @@ double CTeaSort::calculate_angle(
 {
 	grab_x = grab_y = 0.0;
 	double angle = 0.0;
-	float x3,y3,x4,y4,x5,y5;
+	float x2, y2, x3,y3,x4,y4,x5,y5;
+	x2 = b.ppoint[2];
+	y2 = b.ppoint[3];
 	x3 = b.ppoint[4];
 	y3 = b.ppoint[5];
 	x4 = b.ppoint[6];
@@ -425,7 +427,7 @@ double CTeaSort::calculate_angle(
 	}
 	else {
 		//tea cut, calculate line of p3 ans p4
-		angle = atan2(x3 - x4, y3 - y4);
+		angle = atan2(x2 - x3, y2 - y3);
 		calculate_stem_cut_position_opt(b, grab_x, grab_y, angle);
 	}
 	
@@ -1446,14 +1448,14 @@ 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]));
+	cv::Point p2o(int(b.ppoint[2]), int(b.ppoint[3]));
 
 	int x1, y1, x2, y2;
-	x1 = min(p3o.x, p4o.x);
-	y1 = min(p3o.y, p4o.y);
+	x1 = min(p3o.x, p2o.x);
+	y1 = min(p3o.y, p2o.y);
 
-	x2 = max(p3o.x, p4o.x);
-	y2 = max(p3o.y, p4o.y);
+	x2 = max(p3o.x, p2o.x);
+	y2 = max(p3o.y, p2o.y);
 
 	x1 -= padding;
 	x1 = x1 < 0 ? 0 : x1;
@@ -1469,15 +1471,15 @@ void CTeaSort::calculate_stem_cut_position_opt(
 
 	
 	cv::Point p3(int(b.ppoint[4] - x1), int(b.ppoint[5] - y1));
-	cv::Point p4(int(b.ppoint[6] - x1), int(b.ppoint[7] - y1));
+	cv::Point p2(int(b.ppoint[2] - x1), int(b.ppoint[3] - y1));
 	
 	cv::Mat crop_img;
 	crop_img = m_raw_img(cv::Range(y1, y2), cv::Range(x1, x2)).clone();
 	
 	if (m_cp.image_show) {
 		cv::Mat crop_img_tmp = crop_img.clone();
-		cv::circle(crop_img_tmp, p3, 4, cv::Scalar(255, 0, 0), -1, 3, 0);
-		cv::circle(crop_img_tmp, p4, 4, cv::Scalar(0, 255, 0), -1, 3, 0);
+		cv::circle(crop_img_tmp, p2, 4, cv::Scalar(255, 0, 0), -1, 3, 0);
+		cv::circle(crop_img_tmp, p3, 4, cv::Scalar(0, 255, 0), -1, 3, 0);
 		imshow_wait("cropped box", crop_img_tmp);
 	}
 
@@ -1504,8 +1506,9 @@ void CTeaSort::calculate_stem_cut_position_opt(
 	}
 	
 	cv::Point2f center_pt;
-	center_pt.x = 0.5*(p3.x + p4.x);
-	center_pt.y = 0.5*(p3.y + p4.y);
+	double p3_ratio = 0.8;
+	center_pt.x = p3_ratio*p3.x + (1.0 - p3_ratio)*p2.x;
+	center_pt.y = p3_ratio*p3.y + (1.0 - p3_ratio)*p2.y;
 
 	//检查center_pt附近,是否有目标,如果有就用center_pt点作为切割点