|
@@ -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;
|
|
|
|