@@ -6,7 +6,7 @@ mod segment_merger;
6
6
use std:: { collections:: HashSet , ops:: Range } ;
7
7
8
8
use color_eyre:: Result ;
9
- use geometry:: line_segment:: LineSegment ;
9
+ use geometry:: { line :: Line , line_segment:: LineSegment , two_lines :: TwoLines } ;
10
10
use itertools:: Itertools ;
11
11
use rand:: SeedableRng ;
12
12
use rand_chacha:: ChaChaRng ;
@@ -17,7 +17,7 @@ use coordinate_systems::{Ground, Pixel};
17
17
use framework:: { AdditionalOutput , MainOutput } ;
18
18
use linear_algebra:: { distance, Point2 } ;
19
19
use projection:: { camera_matrix:: CameraMatrix , Projection } ;
20
- use ransac:: { Ransac , RansacLineSegment } ;
20
+ use ransac:: { Ransac , RansacFeature , RansacLineSegment } ;
21
21
use types:: {
22
22
filtered_segments:: FilteredSegments ,
23
23
image_segments:: GenericSegment ,
@@ -44,6 +44,7 @@ pub struct CycleContext {
44
44
AdditionalOutput < Vec < ( LineSegment < Pixel > , LineDiscardReason ) > , "discarded_lines" > ,
45
45
filtered_segments_output :
46
46
AdditionalOutput < Vec < GenericSegment > , "line_detection.filtered_segments" > ,
47
+ detected_features : AdditionalOutput < Vec < RansacFeature < Pixel > > , "detected_features" > ,
47
48
48
49
use_horizontal_segments :
49
50
Parameter < bool , "line_detection.$cycler_instance.use_horizontal_segments" > ,
@@ -160,21 +161,23 @@ impl LineDetection {
160
161
. unzip ( ) ;
161
162
162
163
let mut ransac = Ransac :: new ( line_points) ;
164
+ let mut detected_features = Vec :: new ( ) ;
163
165
let mut line_segments = Vec :: new ( ) ;
164
166
let mut discarded_line_segments = Vec :: new ( ) ;
165
167
166
168
for _ in 0 ..* context. maximum_number_of_features {
167
169
if ransac. unused_points . len ( ) < * context. minimum_number_of_points_on_line {
168
170
break ;
169
171
}
170
- let ransac_feature = ransac. next_feature (
172
+ let ransac_result = ransac. next_feature (
171
173
& mut self . random_state ,
172
174
* context. ransac_iterations ,
173
175
* context. maximum_fit_distance_in_ground ,
174
176
* context. maximum_fit_distance_in_ground + * context. margin_for_point_inclusion ,
175
177
) ;
178
+ detected_features. push ( ransac_result. feature . clone ( ) ) ;
176
179
177
- for line_segment in ransac_feature {
180
+ for line_segment in ransac_result {
178
181
let RansacLineSegment {
179
182
line_segment,
180
183
sorted_used_points,
@@ -231,6 +234,40 @@ impl LineDetection {
231
234
}
232
235
}
233
236
237
+ context. detected_features . fill_if_subscribed ( || {
238
+ detected_features
239
+ . into_iter ( )
240
+ . map ( |feature| match feature {
241
+ RansacFeature :: None => RansacFeature :: None ,
242
+ RansacFeature :: Line ( line) => RansacFeature :: Line ( Line :: from_points (
243
+ context. camera_matrix . ground_to_pixel ( line. point ) . unwrap ( ) ,
244
+ context
245
+ . camera_matrix
246
+ . ground_to_pixel ( line. point + line. direction )
247
+ . unwrap ( ) ,
248
+ ) ) ,
249
+ RansacFeature :: TwoLines ( two_lines) => {
250
+ let point = context
251
+ . camera_matrix
252
+ . ground_to_pixel ( two_lines. point )
253
+ . unwrap ( ) ;
254
+ RansacFeature :: TwoLines ( TwoLines {
255
+ point,
256
+ direction1 : context
257
+ . camera_matrix
258
+ . ground_to_pixel ( two_lines. point + two_lines. direction1 . normalize ( ) )
259
+ . unwrap_or ( point)
260
+ - point,
261
+ direction2 : context
262
+ . camera_matrix
263
+ . ground_to_pixel ( two_lines. point + two_lines. direction2 . normalize ( ) )
264
+ . unwrap_or ( point)
265
+ - point,
266
+ } )
267
+ }
268
+ } )
269
+ . collect ( )
270
+ } ) ;
234
271
context. lines_in_image . fill_if_subscribed ( || {
235
272
line_segments
236
273
. iter ( )
0 commit comments