|
@@ -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点作为切割点
|
|
|
|