@@ -16,6 +16,13 @@ const ROW_SCAN_SKIP: u32 = 2;
16
16
pub struct MaxicodeDetectionResult {
17
17
bits : BitMatrix ,
18
18
points : Vec < RXingResultPoint > ,
19
+ rotation : f32 ,
20
+ }
21
+
22
+ impl MaxicodeDetectionResult {
23
+ pub fn rotation ( & self ) -> f32 {
24
+ self . rotation
25
+ }
19
26
}
20
27
21
28
impl DetectorRXingResult for MaxicodeDetectionResult {
@@ -339,7 +346,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
339
346
} ;
340
347
let grid_sampler = DefaultGridSampler :: default ( ) ;
341
348
342
- let [ tl, bl, tr, br] = & symbol_box;
349
+ let [ tl, bl, tr, br] = & symbol_box. 0 ;
343
350
344
351
let target_width = MathUtils :: distance_float ( tl. 0 , tl. 1 , tr. 0 , tr. 1 ) ;
345
352
let target_height = MathUtils :: distance_float ( br. 0 , br. 1 , tr. 0 , tr. 1 ) ;
@@ -377,9 +384,11 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
377
384
return Ok ( MaxicodeDetectionResult {
378
385
bits,
379
386
points : symbol_box
387
+ . 0
380
388
. iter ( )
381
389
. map ( |p| RXingResultPoint { x : p. 0 , y : p. 1 } )
382
390
. collect ( ) ,
391
+ rotation : symbol_box. 1 ,
383
392
} ) ;
384
393
}
385
394
@@ -702,7 +711,10 @@ const LEFT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
702
711
const RIGHT_SHIFT_PERCENT_ADJUST : f32 = 0.03 ;
703
712
const ACCEPTED_SCALES : [ f64 ; 5 ] = [ 0.065 , 0.069 , 0.07 , 0.075 , 0.08 ] ;
704
713
705
- fn box_symbol ( image : & BitMatrix , circle : & mut Circle ) -> Result < [ ( f32 , f32 ) ; 4 ] , Exceptions > {
714
+ fn box_symbol (
715
+ image : & BitMatrix ,
716
+ circle : & mut Circle ,
717
+ ) -> Result < ( [ ( f32 , f32 ) ; 4 ] , f32 ) , Exceptions > {
706
718
let ( left_boundary, right_boundary, top_boundary, bottom_boundary) =
707
719
calculate_simple_boundary ( circle, Some ( image) , None , false ) ;
708
720
@@ -725,19 +737,24 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<[(f32, f32); 4],
725
737
return Err ( Exceptions :: NotFoundException ( None ) ) ;
726
738
}
727
739
740
+ let mut final_rotation = 0.0 ;
741
+
728
742
for scale in ACCEPTED_SCALES {
729
743
if let Some ( found_rotation) = attempt_rotation_box ( image, circle, & naive_box, scale) {
730
- result_box = found_rotation;
744
+ ( result_box, final_rotation ) = found_rotation;
731
745
break ;
732
746
}
733
747
}
734
748
735
- Ok ( [
736
- ( result_box[ 0 ] . x , result_box[ 0 ] . y ) ,
737
- ( result_box[ 1 ] . x , result_box[ 1 ] . y ) ,
738
- ( result_box[ 2 ] . x , result_box[ 2 ] . y ) ,
739
- ( result_box[ 3 ] . x , result_box[ 3 ] . y ) ,
740
- ] )
749
+ Ok ( (
750
+ [
751
+ ( result_box[ 0 ] . x , result_box[ 0 ] . y ) ,
752
+ ( result_box[ 1 ] . x , result_box[ 1 ] . y ) ,
753
+ ( result_box[ 2 ] . x , result_box[ 2 ] . y ) ,
754
+ ( result_box[ 3 ] . x , result_box[ 3 ] . y ) ,
755
+ ] ,
756
+ final_rotation,
757
+ ) )
741
758
}
742
759
743
760
fn calculate_simple_boundary (
@@ -794,7 +811,7 @@ fn attempt_rotation_box(
794
811
circle : & mut Circle ,
795
812
naive_box : & [ RXingResultPoint ; 4 ] ,
796
813
center_scale : f64 ,
797
- ) -> Option < [ RXingResultPoint ; 4 ] > {
814
+ ) -> Option < ( [ RXingResultPoint ; 4 ] , f32 ) > {
798
815
// update our circle with a more accurate center point
799
816
circle. calculate_high_accuracy_center ( ) ;
800
817
@@ -938,12 +955,15 @@ fn attempt_rotation_box(
938
955
final_rotation,
939
956
) ;
940
957
941
- Some ( [
942
- RXingResultPoint :: new ( new_1. 0 , new_1. 1 ) ,
943
- RXingResultPoint :: new ( new_2. 0 , new_2. 1 ) ,
944
- RXingResultPoint :: new ( new_3. 0 , new_3. 1 ) ,
945
- RXingResultPoint :: new ( new_4. 0 , new_4. 1 ) ,
946
- ] )
958
+ Some ( (
959
+ [
960
+ RXingResultPoint :: new ( new_1. 0 , new_1. 1 ) ,
961
+ RXingResultPoint :: new ( new_2. 0 , new_2. 1 ) ,
962
+ RXingResultPoint :: new ( new_3. 0 , new_3. 1 ) ,
963
+ RXingResultPoint :: new ( new_4. 0 , new_4. 1 ) ,
964
+ ] ,
965
+ final_rotation,
966
+ ) )
947
967
} else {
948
968
// panic!("couldn't find");
949
969
None
0 commit comments