|
@@ -88,33 +88,33 @@ int CTeaSort::detect(
|
|
//5 detect
|
|
//5 detect
|
|
vector<Bbox> droplets_raw;
|
|
vector<Bbox> droplets_raw;
|
|
int dn = detect_impl(m_raw_img, drop_regions, droplets_raw);
|
|
int dn = detect_impl(m_raw_img, drop_regions, droplets_raw);
|
|
- //if (dn < 2 && m_dtype == img_type::tea_grab) {
|
|
|
|
- // //up-down flip
|
|
|
|
- // cv::Mat flip_img;
|
|
|
|
- // cv::flip(m_raw_img, flip_img, 0);
|
|
|
|
- // if (m_cp.image_show) {
|
|
|
|
- // imshow_wait("flip_img", flip_img);
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // vector<Bbox> droplets_flip;
|
|
|
|
- // int dn_flip = detect_impl(flip_img, drop_regions, droplets_flip);
|
|
|
|
- // for (auto&b: droplets_flip) {
|
|
|
|
- // int y2 = flip_img.rows - b.y1;
|
|
|
|
- // int y1 = flip_img.rows - b.y2;
|
|
|
|
- // b.y1 = y1;
|
|
|
|
- // b.y2 = y2;
|
|
|
|
- //
|
|
|
|
- // for (int i = 0; i < 5; ++i) {
|
|
|
|
- // b.ppoint[2 * i + 1] = flip_img.rows - b.ppoint[2 * i + 1];
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // if (dn_flip > 0) {
|
|
|
|
- // droplets_raw.insert(
|
|
|
|
- // droplets_raw.end(),
|
|
|
|
- // droplets_flip.begin(),
|
|
|
|
- // droplets_flip.end());
|
|
|
|
- // }
|
|
|
|
- //}
|
|
|
|
|
|
+ if (dn < 2 && m_dtype == img_type::tea_grab) {
|
|
|
|
+ //up-down flip
|
|
|
|
+ cv::Mat flip_img;
|
|
|
|
+ cv::flip(m_raw_img, flip_img, 0);
|
|
|
|
+ if (m_cp.image_show) {
|
|
|
|
+ imshow_wait("flip_img", flip_img);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vector<Bbox> droplets_flip;
|
|
|
|
+ int dn_flip = detect_impl(flip_img, drop_regions, droplets_flip);
|
|
|
|
+ for (auto&b: droplets_flip) {
|
|
|
|
+ int y2 = flip_img.rows - b.y1;
|
|
|
|
+ int y1 = flip_img.rows - b.y2;
|
|
|
|
+ b.y1 = y1;
|
|
|
|
+ b.y2 = y2;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 5; ++i) {
|
|
|
|
+ b.ppoint[2 * i + 1] = flip_img.rows - b.ppoint[2 * i + 1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (dn_flip > 0) {
|
|
|
|
+ droplets_raw.insert(
|
|
|
|
+ droplets_raw.end(),
|
|
|
|
+ droplets_flip.begin(),
|
|
|
|
+ droplets_flip.end());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/*for (auto rect : drop_regions) {
|
|
/*for (auto rect : drop_regions) {
|
|
Mat roi = m_raw_img(rect);
|
|
Mat roi = m_raw_img(rect);
|
|
vector<Bbox> head_droplets = m_drop_detector.RunModel(roi, m_pLogger);
|
|
vector<Bbox> head_droplets = m_drop_detector.RunModel(roi, m_pLogger);
|
|
@@ -164,51 +164,75 @@ int CTeaSort::detect(
|
|
|
|
|
|
|
|
|
|
int valid_cnt = 0;
|
|
int valid_cnt = 0;
|
|
- for (int i = 0; i < droplets.size();++i) {
|
|
|
|
- if (i > 1) { break; }
|
|
|
|
- Bbox&b = droplets.at(i);
|
|
|
|
- double grab_x, grab_y;
|
|
|
|
- double angle = calalate_angle(b, grab_x, grab_y);
|
|
|
|
- valid_cnt += 1;
|
|
|
|
- //grab point
|
|
|
|
- if (i == 0) {
|
|
|
|
- if (m_dtype == img_type::tea_grab) {
|
|
|
|
|
|
+ if (m_dtype == img_type::tea_grab) {
|
|
|
|
+ //grab
|
|
|
|
+ double pre_cx, pre_cy;
|
|
|
|
+ double min_dist_grab = m_cp.min_distance_grab;
|
|
|
|
+ pre_cx = -min_dist_grab;
|
|
|
|
+ pre_cy = -min_dist_grab;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < droplets.size(); ++i) {
|
|
|
|
+ if (valid_cnt > 1) { break; }
|
|
|
|
+ Bbox&b = droplets.at(i);
|
|
|
|
+ double cx = 0.5*(b.x1 + b.x2);
|
|
|
|
+ double cy = 0.5*(b.y1 + b.y2);
|
|
|
|
+ double dist = sqrt((cx - pre_cx)*(cx - pre_cx) + (cy - pre_cy)*(cy - pre_cy));
|
|
|
|
+ if (dist < min_dist_grab) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ double grab_x, grab_y;
|
|
|
|
+ double angle = calalate_angle(b, grab_x, grab_y);
|
|
|
|
+
|
|
|
|
+ //grab point
|
|
|
|
+ if (valid_cnt == 0) {
|
|
posinfo.tea_grab_x1 = grab_x;
|
|
posinfo.tea_grab_x1 = grab_x;
|
|
posinfo.tea_grab_y1 = grab_y;
|
|
posinfo.tea_grab_y1 = grab_y;
|
|
- posinfo.tea_grab_angle1 = angle;
|
|
|
|
|
|
+ posinfo.tea_grab_angle1 = angle;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- // 切割点是3、4的中间的点
|
|
|
|
- posinfo.tea_cut_x1 = 0.5 * (b.ppoint[4] + b.ppoint[6]);
|
|
|
|
- posinfo.tea_cut_y1 = 0.5 * (b.ppoint[5] + b.ppoint[7]);
|
|
|
|
- posinfo.tea_cut_angle1 = angle;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if (m_dtype == img_type::tea_grab) {
|
|
|
|
posinfo.tea_grab_x2 = grab_x;
|
|
posinfo.tea_grab_x2 = grab_x;
|
|
posinfo.tea_grab_y2 = grab_y;
|
|
posinfo.tea_grab_y2 = grab_y;
|
|
posinfo.tea_grab_angle2 = angle;
|
|
posinfo.tea_grab_angle2 = angle;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ pre_cx = cx;
|
|
|
|
+ pre_cy = cy;
|
|
|
|
+ b.status = 1;
|
|
|
|
+ valid_cnt += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ //cut
|
|
|
|
+ for (int i = 0; i < droplets.size();++i) {
|
|
|
|
+ if (i > 1) { break; }
|
|
|
|
+ Bbox&b = droplets.at(i);
|
|
|
|
+ b.status = 1; // selected
|
|
|
|
+ double grab_x, grab_y;
|
|
|
|
+ double angle = calalate_angle(b, grab_x, grab_y);
|
|
|
|
+ valid_cnt += 1;
|
|
|
|
+ if (i == 0) {
|
|
|
|
+ // 切割点是3、4的中间的点
|
|
|
|
+ posinfo.tea_cut_x1 = 0.5 * (b.ppoint[4] + b.ppoint[6]);
|
|
|
|
+ posinfo.tea_cut_y1 = 0.5 * (b.ppoint[5] + b.ppoint[7]);
|
|
|
|
+ posinfo.tea_cut_angle1 = angle;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
// 切割点是3、4的中间的点
|
|
// 切割点是3、4的中间的点
|
|
posinfo.tea_cut_x2 = 0.5 * (b.ppoint[4] + b.ppoint[6]);
|
|
posinfo.tea_cut_x2 = 0.5 * (b.ppoint[4] + b.ppoint[6]);
|
|
posinfo.tea_cut_y2 = 0.5 * (b.ppoint[5] + b.ppoint[7]);
|
|
posinfo.tea_cut_y2 = 0.5 * (b.ppoint[5] + b.ppoint[7]);
|
|
posinfo.tea_cut_angle2 = angle;
|
|
posinfo.tea_cut_angle2 = angle;
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
//6 draw
|
|
//6 draw
|
|
if (m_cp.image_return) {
|
|
if (m_cp.image_return) {
|
|
this->clear_imginfo();
|
|
this->clear_imginfo();
|
|
- cv::Mat img_rst = m_raw_img.clone();
|
|
|
|
- int cnt = 0;
|
|
|
|
|
|
+ cv::Mat img_rst = m_raw_img.clone();
|
|
for (auto& b : droplets) {
|
|
for (auto& b : droplets) {
|
|
//rectangle
|
|
//rectangle
|
|
cv::Rect r = cv::Rect(cv::Point2i(b.x1, b.y1), cv::Point2i(b.x2, b.y2));
|
|
cv::Rect r = cv::Rect(cv::Point2i(b.x1, b.y1), cv::Point2i(b.x2, b.y2));
|
|
- if (cnt < 2) {
|
|
|
|
|
|
+ if (b.status > 0) {
|
|
cv::rectangle(img_rst, r, cv::Scalar(0, 0, 255),2);
|
|
cv::rectangle(img_rst, r, cv::Scalar(0, 0, 255),2);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -266,11 +290,8 @@ int CTeaSort::detect(
|
|
cv::line(img_rst, cv::Point(cx - radius, cy - radius), cv::Point(cx + radius, cy + radius), cv::Scalar(0, 215, 255),2);
|
|
cv::line(img_rst, cv::Point(cx - radius, cy - radius), cv::Point(cx + radius, cy + radius), cv::Scalar(0, 215, 255),2);
|
|
cv::line(img_rst, cv::Point(cx - radius, cy + radius), cv::Point(cx + radius, cy - radius), cv::Scalar(0, 215, 255),2);
|
|
cv::line(img_rst, cv::Point(cx - radius, cy + radius), cv::Point(cx + radius, cy - radius), cv::Scalar(0, 215, 255),2);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- cnt += 1;
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
if (m_cp.image_show) {
|
|
if (m_cp.image_show) {
|
|
imshow_wait("result_img", img_rst);
|
|
imshow_wait("result_img", img_rst);
|
|
}
|
|
}
|