44import numpy as np
55
66from .calibration import Calibration
7- from .constants import COORD_UNUSED , CORRES_NONE , MAX_TARGETS , MAXCAND , NMAX , PT_UNUSED
7+ from .constants import (
8+ COORD_UNUSED ,
9+ CORRES_NONE ,
10+ MAX_TARGETS ,
11+ MAXCAND ,
12+ NMAX ,
13+ PT_UNUSED ,
14+ )
815from .epi import epi_mm
916from .find_candidate import find_candidate
1017from .parameters import ControlPar , VolumePar
@@ -44,8 +51,8 @@ def __init__(self, targs, cpar, cal, tol=0.00001, reset_numbers=True):
4451 don't.
4552 """
4653 self ._num_pts = len (targs )
47- self .buf = np .empty (self ._num_pts , \
48- dtype = np .dtype ([('x' , np .float64 ), ('y' , np .float64 ), ('pnr' , np .int32 )]))
54+ self .buf = np .empty (self ._num_pts ,
55+ dtype = np .dtype ([('x' , np .float64 ), ('y' , np .float64 ), ('pnr' , np .int32 )]))
4956
5057 for tnum , targ in enumerate (targs ):
5158 targ = targs [tnum ]
@@ -57,7 +64,7 @@ def __init__(self, targs, cpar, cal, tol=0.00001, reset_numbers=True):
5764
5865 self .buf [tnum ]['x' ], self .buf [tnum ]['y' ] = dist_to_flat (
5966 self .buf [tnum ]['x' ], self .buf [tnum ]['y' ], cal , tol
60- )
67+ )
6168 self .buf [tnum ]['pnr' ] = targ .pnr
6269
6370 self .buf .sort (order = 'x' )
@@ -100,16 +107,17 @@ def __del__(self):
100107
101108
102109Correspond_dtype = np .dtype ([
103- ('p1' , np .int32 ), # PT_UNUSED
104- ('n' , np .int32 ), # 0
105- ('p2' , (np .int32 , MAXCAND )), # np.zeros
106- ('corr' , (np .float64 , MAXCAND )), # np.zeros
107- ('dist' , (np .float64 , MAXCAND )) # np.zeros
110+ ('p1' , np .int32 ), # PT_UNUSED
111+ ('n' , np .int32 ), # 0
112+ ('p2' , (np .int32 , MAXCAND )), # np.zeros
113+ ('corr' , (np .float64 , MAXCAND )), # np.zeros
114+ ('dist' , (np .float64 , MAXCAND )) # np.zeros
108115])
109116
117+
110118def safely_allocate_target_usage_marks (
111119 num_cams : int , nmax : int = NMAX
112- ) -> np .ndarray : # num_cams x nmax instead of List[List[int]]:
120+ ) -> np .ndarray : # num_cams x nmax instead of List[List[int]]:
113121 """Allocate space for per-camera arrays marking whether a certain target was used.
114122
115123 If some allocation failed, it cleans up memory and returns NULL. Allocated arrays are zeroed
@@ -134,6 +142,7 @@ def safely_allocate_target_usage_marks(
134142
135143 return np .zeros ((num_cams , nmax ), dtype = np .int32 )
136144
145+
137146def safely_allocate_adjacency_lists (
138147 num_cams : int , target_counts : List [int ]
139148) -> np .recarray :
@@ -148,7 +157,8 @@ def safely_allocate_adjacency_lists(
148157 # for c1 in range(num_cams)
149158 # ]
150159
151- lists = np .recarray ((num_cams , num_cams , max (target_counts )),dtype = Correspond_dtype )
160+ lists = np .recarray ((num_cams , num_cams , max (
161+ target_counts )), dtype = Correspond_dtype )
152162
153163 except MemoryError as exc :
154164 raise MemoryError ("Failed to allocate adjacency lists." ) from exc
@@ -160,9 +170,9 @@ def safely_allocate_adjacency_lists(
160170 lists .corr = np .zeros (MAXCAND )
161171 lists .dist = np .zeros (MAXCAND )
162172
163-
164173 return lists
165174
175+
166176def four_camera_matching (
167177 corr_list : np .recarray ,
168178 base_target_count ,
@@ -240,7 +250,7 @@ def four_camera_matching(
240250
241251
242252def three_camera_matching (
243- corr_list : np .recarray , # num_cam, num_cam, num_targets
253+ corr_list : np .recarray , # num_cam, num_cam, num_targets
244254 num_cams ,
245255 target_counts ,
246256 accept_corr ,
@@ -345,7 +355,8 @@ def consistent_pair_matching(
345355 if p2 >= nmax or tusage [i2 ][p2 ] > 0 :
346356 continue
347357
348- corr = corr_list [i1 ][i2 ][i ].corr [0 ] / corr_list [i1 ][i2 ][i ].dist [0 ]
358+ corr = corr_list [i1 ][i2 ][i ].corr [0 ] / \
359+ corr_list [i1 ][i2 ][i ].dist [0 ]
349360 if corr <= accept_corr :
350361 continue
351362
@@ -365,8 +376,8 @@ def consistent_pair_matching(
365376
366377
367378def match_pairs (
368- corr_lists : np .recarray , # num_cam, num_cam, num_targets
369- corrected : np .recarray , # List[List[Coord2d]],
379+ corr_lists : np .recarray , # num_cam, num_cam, num_targets
380+ corrected : np .recarray , # List[List[Coord2d]],
370381 frm : Frame ,
371382 vpar : VolumePar ,
372383 cpar : ControlPar ,
@@ -466,7 +477,8 @@ def match_pairs(
466477
467478
468479def take_best_candidates (
469- src : np .recarray , dst : np .recarray , num_cams : int , tusage : np .ndarray #List[n_tupel]
480+ # List[n_tupel]
481+ src : np .recarray , dst : np .recarray , num_cams : int , tusage : np .ndarray
470482):
471483 """
472484 Take the best candidates from the candidate list based on their correlation measure.
@@ -509,8 +521,8 @@ def take_best_candidates(
509521 taken = 0
510522
511523 # Sort candidates by match quality (.corr)
512- src .sort (order = 'corr' ) # by corr
513- src = src [::- 1 ] # reverse order
524+ src .sort (order = 'corr' ) # by corr
525+ src = src [::- 1 ] # reverse order
514526
515527 # Take candidates from the top to the bottom of the sorted list
516528 # Only take if none of the corresponding targets have been used
@@ -613,7 +625,8 @@ def py_correspondences(
613625 frm .targets [cam ] = img_pts [cam ]
614626
615627 # The biz:
616- corresp_buf = correspondences (frm , flat_coords , vparam , cparam , calib , match_counts )
628+ corresp_buf = correspondences (
629+ frm , flat_coords , vparam , cparam , calib , match_counts )
617630
618631 # Distribute data to return structures:
619632 # sorted_pos = [None] * (num_cams - 1)
@@ -623,9 +636,12 @@ def py_correspondences(
623636 last_count = 0
624637
625638 for clique_type in range (num_cams - 1 ):
626- num_points = match_counts [4 - num_cams + clique_type ] # for 1-4 cameras
627- clique_targs = np .full ((num_cams , num_points , 2 ), PT_UNUSED , dtype = np .float64 )
628- clique_ids = np .full ((num_cams , num_points ), CORRES_NONE , dtype = np .int_ )
639+ num_points = match_counts [4 - num_cams +
640+ clique_type ] # for 1-4 cameras
641+ clique_targs = np .full ((num_cams , num_points , 2 ),
642+ PT_UNUSED , dtype = np .float64 )
643+ clique_ids = np .full ((num_cams , num_points ),
644+ CORRES_NONE , dtype = np .int_ )
629645
630646 # Trace back the pixel target properties through the flat metric
631647 # intermediary that's x-sorted.
@@ -662,7 +678,7 @@ def correspondences(
662678 cpar : ControlPar ,
663679 calib : List [Calibration ],
664680 match_counts : List [int ],
665- ) -> np .recarray : # n_tupel_dtype
681+ ) -> np .recarray : # n_tupel_dtype
666682 """Find correspondences between cameras.
667683
668684 /* correspondences() generates a list of tuple target numbers (one for each
@@ -699,8 +715,13 @@ def correspondences(
699715 nmax = NMAX
700716
701717 # Allocation of scratch buffers for internal tasks and return-value space
702- con0 = np .recarray ((nmax * cpar .num_cams ), dtype = n_tupel_dtype )
703- con = np .recarray ((nmax * cpar .num_cams ), dtype = n_tupel_dtype )
718+ con0 = np .recarray ((nmax * cpar .num_cams ,), dtype = n_tupel_dtype )
719+ con0 .p = 0
720+ con0 .corr = 0.0
721+
722+ con = np .recarray ((nmax * cpar .num_cams ,), dtype = n_tupel_dtype )
723+ con .p = 0
724+ con .corr = 0.0
704725
705726 tim = safely_allocate_target_usage_marks (cpar .num_cams , nmax )
706727
@@ -732,7 +753,7 @@ def correspondences(
732753 )
733754
734755 match_counts [1 ] = take_best_candidates (
735- con0 , con [match_counts [3 ] :], cpar .num_cams , tim
756+ con0 , con [match_counts [3 ]:], cpar .num_cams , tim
736757 )
737758 match_counts [3 ] += match_counts [1 ]
738759
@@ -742,7 +763,7 @@ def correspondences(
742763 corr_list , cpar .num_cams , frm .num_targets , vpar .corrmin , con0 , 4 * nmax , tim
743764 )
744765 match_counts [2 ] = take_best_candidates (
745- con0 , con [match_counts [3 ] :], cpar .num_cams , tim
766+ con0 , con [match_counts [3 ]:], cpar .num_cams , tim
746767 )
747768 match_counts [3 ] += match_counts [2 ]
748769
@@ -766,7 +787,7 @@ def correspondences(
766787
767788
768789def single_cam_correspondences (
769- img_pts : List [Target ], corrected : np .recarray # List[Coord2d]
790+ img_pts : List [Target ], corrected : np .recarray # List[Coord2d]
770791) -> Tuple [List [np .ndarray ], List [np .ndarray ], int ]:
771792 """
772793 Single camera correspondence is not a real correspondence, it will be only a projection.
0 commit comments