Skip to content

Commit 9ca33dc

Browse files
committed
Send the image when lane estimation is failed
1 parent 52ff2b1 commit 9ca33dc

File tree

2 files changed

+112
-17
lines changed

2 files changed

+112
-17
lines changed

system/lane_detector.cpp

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void LaneDetector::segment_homography_transform(vector<segment_t>& lines)
441441
}
442442
}
443443

444-
void LaneDetector::send_visualize_image_to_queue(
444+
void LaneDetector::send_sucess_visualize_image_thread(
445445
/* Images */
446446
cv::Mat distorted_image, cv::Mat canny_image,
447447
cv::Mat outer_threshold_image, cv::Mat inner_threshold_image,
@@ -485,6 +485,75 @@ void LaneDetector::send_visualize_image_to_queue(
485485
ROS_INFO("phi:%f | d:%f", phi, d);
486486
}
487487

488+
void LaneDetector::send_failed_visualize_image_thread(
489+
/* Images */
490+
cv::Mat distorted_image, cv::Mat canny_image,
491+
cv::Mat outer_threshold_image, cv::Mat inner_threshold_image)
492+
{
493+
cv::Mat lane_mark_image = distorted_image;
494+
495+
#if 1
496+
/* Bird view image */
497+
cv::Mat bird_view_image;
498+
draw_bird_view_image(distorted_image, bird_view_image);
499+
#endif
500+
501+
draw_region_of_interest(lane_mark_image);
502+
503+
/* Draw car status */
504+
putText(lane_mark_image, "Failed to estimate the lane", Point(10, 15),
505+
FONT_HERSHEY_COMPLEX_SMALL, 0.7, Scalar(0, 0, 255));
506+
507+
publish_images(
508+
lane_mark_image, canny_image,
509+
outer_threshold_image, inner_threshold_image,
510+
bird_view_image
511+
);
512+
513+
ROS_INFO("Failed to estimate the lane");
514+
}
515+
516+
517+
void LaneDetector::send_visualize_image(
518+
/* Images */
519+
cv::Mat& distorted_image, cv::Mat& canny_image,
520+
cv::Mat& outer_threshold_image, cv::Mat& inner_threshold_image,
521+
/* Segments */
522+
vector<segment_t>& outer_lines, vector<segment_t>& inner_lines,
523+
/* Pose */
524+
float& d, float& phi, xenobot::segmentArray& segments_msg)
525+
{
526+
thread send_image_thread(
527+
&LaneDetector::send_sucess_visualize_image_thread,
528+
this,
529+
distorted_image,
530+
canny_image,
531+
outer_threshold_image,
532+
inner_threshold_image,
533+
outer_lines, inner_lines,
534+
d, phi, segments_msg
535+
);
536+
537+
send_image_thread.detach();
538+
}
539+
540+
void LaneDetector::send_visualize_image(
541+
/* Images */
542+
cv::Mat& distorted_image, cv::Mat& canny_image,
543+
cv::Mat& outer_threshold_image, cv::Mat& inner_threshold_image)
544+
{
545+
thread send_image_thread(
546+
&LaneDetector::send_failed_visualize_image_thread,
547+
this,
548+
distorted_image,
549+
canny_image,
550+
outer_threshold_image,
551+
inner_threshold_image
552+
);
553+
554+
send_image_thread.detach();
555+
}
556+
488557
bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& final_phi)
489558
{
490559
/* Find the region of interest for lane */
@@ -540,7 +609,13 @@ bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& fina
540609
segments_side_recognize(inner_cv_lines, inner_xeno_lines, inner_threshold_image);
541610

542611
if(outer_xeno_lines.size() == 0 && inner_xeno_lines.size() == 0) {
543-
pose_available = false;
612+
send_visualize_image(
613+
raw_image,
614+
canny_image,
615+
outer_threshold_image,
616+
inner_threshold_image
617+
);
618+
544619
return false;
545620
}
546621

@@ -644,7 +719,13 @@ bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& fina
644719
}
645720

646721
if(vote_box[highest_vote_i][highest_vote_j] < HISTOGRAM_FILTER_THRESHOLD) {
647-
pose_available = false;
722+
send_visualize_image(
723+
raw_image,
724+
canny_image,
725+
outer_threshold_image,
726+
inner_threshold_image
727+
);
728+
648729
return false;
649730
}
650731

@@ -696,14 +777,22 @@ bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& fina
696777
}
697778
}
698779

699-
if(phi_sample_cnt == 0) return false;
700-
if(d_sample_cnt == 0) return false;
780+
if(phi_sample_cnt == 0 || d_sample_cnt == 0) {
781+
send_visualize_image(
782+
raw_image,
783+
canny_image,
784+
outer_threshold_image,
785+
inner_threshold_image
786+
);
787+
788+
return false;
789+
}
701790

702791
phi_mean /= (float)phi_sample_cnt;
703792
d_mean /= (float)d_sample_cnt;
704793

705-
final_d = pose_d = d_mean;
706-
final_phi = pose_phi = phi_mean;
794+
final_d = d_mean;
795+
final_phi = phi_mean;
707796

708797
#if 1
709798
//ROS message
@@ -713,9 +802,7 @@ bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& fina
713802
segments_msg.segments.push_back(segment);
714803
#endif
715804

716-
thread send_image_thread(
717-
&LaneDetector::send_visualize_image_to_queue,
718-
this,
805+
send_visualize_image(
719806
raw_image,
720807
canny_image,
721808
outer_threshold_image,
@@ -724,8 +811,6 @@ bool LaneDetector::lane_estimate(cv::Mat& raw_image, float& final_d, float& fina
724811
final_d, final_phi, segments_msg
725812
);
726813

727-
send_image_thread.detach();
728-
729814
return true;
730815
}
731816

system/lane_detector.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ class LaneDetector {
9191

9292
cv::Mat* H; //Homography matrix
9393

94-
float pose_d;
95-
float pose_phi;
96-
bool pose_available;
97-
9894
float roi_offset_x;
9995
float roi_offset_y;
10096

@@ -131,12 +127,26 @@ class LaneDetector {
131127
void draw_segment_side(cv::Mat& lane_mark_image, vector<segment_t>& xeno_segments);
132128
void draw_bird_view_image(cv::Mat& original_image, cv::Mat& bird_view_image);
133129
void draw_region_of_interest(cv::Mat lane_mark_image);
134-
void send_visualize_image_to_queue(
130+
131+
void send_sucess_visualize_image_thread(
135132
cv::Mat distorted_image, cv::Mat canny_image,
136133
cv::Mat outer_threshold_image, cv::Mat inner_threshold_image,
137134
vector<segment_t> outer_lines, vector<segment_t> inner_lines,
138135
float d, float phi, xenobot::segmentArray segments_msg);
139136

137+
void send_failed_visualize_image_thread(
138+
cv::Mat distorted_image, cv::Mat canny_image,
139+
cv::Mat outer_threshold_image, cv::Mat inner_threshold_image);
140+
141+
void send_visualize_image(
142+
cv::Mat& distorted_image, cv::Mat& canny_image,
143+
cv::Mat& outer_threshold_image, cv::Mat& inner_threshold_image,
144+
vector<segment_t>& outer_lines, vector<segment_t>& inner_lines,
145+
float& d, float& phi, xenobot::segmentArray& segments_msg);
146+
147+
void send_visualize_image(cv::Mat& distorted_image, cv::Mat& canny_image,
148+
cv::Mat& outer_threshold_image, cv::Mat& inner_threshold_image);
149+
140150
public:
141151
LaneDetector(string yaml_path, bool calibrate_mode);
142152

0 commit comments

Comments
 (0)