Prechádzať zdrojové kódy

v0.1.23 抓取点以关键点4为基础偏移

chenhongjiang 1 rok pred
rodič
commit
0bae65f63d
4 zmenil súbory, kde vykonal 15 pridanie a 14 odobranie
  1. 2 1
      ReadMe.txt
  2. 2 2
      tcv_conf.yml
  3. 1 1
      tea_cv_api.cpp
  4. 10 10
      tea_sorter.cpp

+ 2 - 1
ReadMe.txt

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

+ 2 - 2
tcv_conf.yml

@@ -6,7 +6,7 @@ conf_parameters:
    image_save: 1
    image_depository: "D:\\logs\\algo_img"
    image_backup_days: 7
-   model_path_grab: "D:/projects/graft/py_code/retina_tea5/TeaDetector_grab_20231205234724.onnx"
+   model_path_grab: "D:/projects/graft/py_code/retina_tea5/TeaDetector_grab_20231223061511.onnx"
    object_threshold_grab: 0.65
    nms_threshold_grab: 1.0000000149011612e-01
    grid_row_grab: 2
@@ -15,7 +15,7 @@ conf_parameters:
    offset_grab: 330
    min_distance_grab: 501.
    min_area_ratio_grab: 0.0
-   max_area_ratio_grab: 0.1
+   max_area_ratio_grab: 0.07
    rot_degree_grab: 0
    model_path_cut: "D:/projects/graft/py_code/retina_tea5/TeaDetector_cut_20231219003541.onnx"
    object_threshold_cut: 0.8

+ 1 - 1
tea_cv_api.cpp

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

+ 10 - 10
tea_sorter.cpp

@@ -1262,8 +1262,8 @@ void CTeaSort::calculate_stem_grab_position_opt(
 		//在指定方向的矩形框内,找到内部点最多的方向,作为主方向
 		double target_angle = ref_angle_init + i*step_angle;
 		cv::Point center_pt;
-		center_pt.x = p5.x + static_cast<int>(radius * sin(target_angle));
-		center_pt.y = p5.y + static_cast<int>(radius * cos(target_angle));
+		center_pt.x = p4.x + static_cast<int>(radius * sin(target_angle));
+		center_pt.y = p4.y + static_cast<int>(radius * cos(target_angle));
 		calc_bottom_vertex(center_pt, target_angle, delta_angle, radius, pt0, pt1);
 		calc_bottom_vertex(center_pt, target_angle + CV_PI, delta_angle, radius, pt2, pt3);
 
@@ -1317,7 +1317,7 @@ void CTeaSort::calculate_stem_grab_position_opt(
 	if (m_cp.image_show) {
 		cv::Mat bin_tmp = ske_img.clone();
 
-		cv::circle(bin_tmp, p5, 4, cv::Scalar(156, 0, 255), 1, 3, 0);
+		cv::circle(bin_tmp, p4, 4, cv::Scalar(156, 0, 255), 1, 3, 0);
 		cv::circle(bin_tmp, pt0_opt, 4, cv::Scalar(156, 0, 255), 1, 3, 0);
 		cv::circle(bin_tmp, pt1_opt, 4, cv::Scalar(156, 0, 255), 1, 3, 0);
 		cv::circle(bin_tmp, pt2_opt, 4, cv::Scalar(156, 0, 255), 1, 3, 0);
@@ -1368,20 +1368,20 @@ void CTeaSort::calculate_stem_grab_position_opt(
 	}*/
 
 
-	//遍历所有点,找到距离等于指定距离的点的位置, 以及距离p5最近的骨架上的点
+	//遍历所有点,找到距离等于指定距离的点的位置, 以及距离p4最近的骨架上的点
 	std::vector<cv::Point> candidate_pts;
-	cv::Point p5_nearst;
+	cv::Point p4_nearst;
 	double dist_th = 5;
 	double dist_min = 1.0e6;
 	for (auto& pt : ske_pixels_opt) {
 		int c = int(pt.x);
 		int r = int(pt.y);
-		double dist = std::powf((p5.x - c), 2) + std::powf((p5.y - r), 2);
+		double dist = std::powf((p4.x - c), 2) + std::powf((p4.y - r), 2);
 		dist = std::sqrtf(dist);
 		if (dist < dist_min) {
 			dist_min = dist;
-			p5_nearst.x = c;
-			p5_nearst.y = r;
+			p4_nearst.x = c;
+			p4_nearst.y = r;
 		}
 		if (std::fabs(dist - m_cp.offset_grab) < dist_th) {
 			candidate_pts.push_back(cv::Point(c, r));
@@ -1415,7 +1415,7 @@ void CTeaSort::calculate_stem_grab_position_opt(
 		for (auto&p : valid_candidate_pts) {
 			ske_img_tmp.at<unsigned char>(p) = 100;
 		}
-		cv::circle(ske_img_tmp, p5, 4, cv::Scalar(255, 0, 255), 1, 3, 0);
+		cv::circle(ske_img_tmp, p4, 4, cv::Scalar(255, 0, 255), 1, 3, 0);
 		if (grab_x > 0 && grab_y > 0) {
 			cv::circle(ske_img_tmp, cv::Point(int(grab_x), int(grab_y)), 4, cv::Scalar(156, 0, 255), 1, 3, 0);
 		}
@@ -1429,7 +1429,7 @@ void CTeaSort::calculate_stem_grab_position_opt(
 
 	//重新得到grab_x,grab_y的坐标
 	if (grab_x > 0 && grab_y > 0) {
-		int real_padding_y = p5.y - int(b.ppoint[9] - b.y1);
+		int real_padding_y = p4.y - int(b.ppoint[7] - b.y1);
 		grab_y -= real_padding_y;
 		grab_y += b.y1;
 		grab_x += b.x1;