|
5 | 5 |
|
6 | 6 | from .calibration import Calibration |
7 | 7 | from .constants import COORD_UNUSED, CORRES_NONE, MAX_TARGETS, MAXCAND, NMAX, PT_UNUSED |
8 | | -from .epi import Coord2d, epi_mm |
| 8 | +from .epi import epi_mm |
9 | 9 | from .find_candidate import find_candidate |
10 | 10 | from .parameters import ControlPar, VolumePar |
11 | | -from .tracking_frame_buf import Frame, Target, n_tupel |
| 11 | +from .tracking_frame_buf import Frame, Target, n_tupel_dtype |
12 | 12 | from .trafo import dist_to_flat, pixel_to_metric |
13 | 13 |
|
14 | 14 |
|
@@ -99,15 +99,13 @@ def __del__(self): |
99 | 99 | del self.buf |
100 | 100 |
|
101 | 101 |
|
102 | | -class Correspond: |
103 | | - """Correspondence between two points in two cameras.""" |
104 | | - |
105 | | - def __init__(self): |
106 | | - self.p1 = PT_UNUSED |
107 | | - self.n = 0 |
108 | | - self.p2 = np.array([0] * MAXCAND) |
109 | | - self.corr = np.array([0.0] * MAXCAND) |
110 | | - self.dist = np.array([0.0] * MAXCAND) |
| 102 | +Correspond_dtype = np.dtype([ |
| 103 | + ('p1', np.int32), # PT_UNUSED |
| 104 | + ('n', np.int32), # 0 |
| 105 | + ('p2', (np.float64, MAXCAND)), # np.zeros |
| 106 | + ('corr', (np.float64, MAXCAND)), # np.zeros |
| 107 | + ('dist', (np.float64, MAXCAND)) # np.zeros |
| 108 | +]) |
111 | 109 |
|
112 | 110 | def safely_allocate_target_usage_marks( |
113 | 111 | num_cams: int, nmax: int = NMAX |
@@ -138,21 +136,26 @@ def safely_allocate_target_usage_marks( |
138 | 136 |
|
139 | 137 | def safely_allocate_adjacency_lists( |
140 | 138 | num_cams: int, target_counts: List[int] |
141 | | -) -> List[List[List[Correspond]]]: |
| 139 | +) -> List[List[List[np.recarray]]]: |
142 | 140 | """Allocate space for the adjacency lists.""" |
| 141 | + one_element = np.array( |
| 142 | + [(PT_UNUSED, 0, np.zeros(MAXCAND), np.zeros(MAXCAND), np.zeros(MAXCAND))], |
| 143 | + dtype=Correspond_dtype).view(np.recarray) |
| 144 | + |
143 | 145 | try: |
144 | 146 | lists = [ |
145 | | - [[Correspond() for _ in range(target_counts[c1])] for _ in range(num_cams)] |
| 147 | + [[one_element for _ in range(target_counts[c1])] for _ in range(num_cams)] |
146 | 148 | for c1 in range(num_cams) |
147 | 149 | ] |
| 150 | + |
148 | 151 | except MemoryError: |
149 | 152 | print("Memory allocation failed.") |
150 | | - lists = [] |
| 153 | + lists = [[[one_element]]] |
151 | 154 |
|
152 | 155 | return lists |
153 | 156 |
|
154 | 157 | def four_camera_matching( |
155 | | - corr_list: List[List[List[Correspond]]], |
| 158 | + corr_list: List[List[List[np.recarray]]], |
156 | 159 | base_target_count, |
157 | 160 | accept_corr, |
158 | 161 | scratch, |
@@ -228,7 +231,7 @@ def four_camera_matching( |
228 | 231 |
|
229 | 232 |
|
230 | 233 | def three_camera_matching( |
231 | | - corr_list: List[List[List[Correspond]]], |
| 234 | + corr_list: List[List[List[np.recarray]]], |
232 | 235 | num_cams, |
233 | 236 | target_counts, |
234 | 237 | accept_corr, |
@@ -307,7 +310,7 @@ def three_camera_matching( |
307 | 310 |
|
308 | 311 |
|
309 | 312 | def consistent_pair_matching( |
310 | | - corr_list: List[List[List[Correspond]]], |
| 313 | + corr_list: List[List[List[np.recarray]]], |
311 | 314 | num_cams: int, |
312 | 315 | target_counts: List[int], |
313 | 316 | accept_corr: float, |
@@ -353,8 +356,8 @@ def consistent_pair_matching( |
353 | 356 |
|
354 | 357 |
|
355 | 358 | def match_pairs( |
356 | | - corr_lists: List[List[List[Correspond]]], |
357 | | - corrected: List[List[Coord2d]], |
| 359 | + corr_lists: List[List[List[np.recarray]]], |
| 360 | + corrected: np.ndarray, # List[List[Coord2d]], |
358 | 361 | frm: Frame, |
359 | 362 | vpar: VolumePar, |
360 | 363 | cpar: ControlPar, |
@@ -454,7 +457,7 @@ def match_pairs( |
454 | 457 |
|
455 | 458 |
|
456 | 459 | def take_best_candidates( |
457 | | - src: List[n_tupel], dst: List[n_tupel], num_cams: int, tusage: List[List[int]] |
| 460 | + src: np.recarray, dst: np.recarray, num_cams: int, tusage: List[List[int]] #List[n_tupel] |
458 | 461 | ): |
459 | 462 | """ |
460 | 463 | Take the best candidates from the candidate list based on their correlation measure. |
@@ -497,7 +500,8 @@ def take_best_candidates( |
497 | 500 | taken = 0 |
498 | 501 |
|
499 | 502 | # Sort candidates by match quality (.corr) |
500 | | - src.sort(key=lambda x: x.corr, reverse=True) |
| 503 | + src.sort(order='corr') # by corr |
| 504 | + src = src[::-1] # reverse order |
501 | 505 |
|
502 | 506 | # Take candidates from the top to the bottom of the sorted list |
503 | 507 | # Only take if none of the corresponding targets have been used |
@@ -528,7 +532,7 @@ def take_best_candidates( |
528 | 532 |
|
529 | 533 | def py_correspondences( |
530 | 534 | img_pts: List[List[Target]], # num_cams * num_targets[cam] |
531 | | - flat_coords: List[List[Coord2d]], |
| 535 | + flat_coords: List[List[np.recarray]], |
532 | 536 | calib: List[Calibration], |
533 | 537 | vparam: VolumePar, |
534 | 538 | cparam: ControlPar, |
@@ -644,12 +648,12 @@ def py_correspondences( |
644 | 648 |
|
645 | 649 | def correspondences( |
646 | 650 | frm: Frame, |
647 | | - corrected: List[List[Coord2d]], |
| 651 | + corrected: List[List[np.recarray]], # List[List[Coord2d]], |
648 | 652 | vpar: VolumePar, |
649 | 653 | cpar: ControlPar, |
650 | 654 | calib: List[Calibration], |
651 | 655 | match_counts: List[int], |
652 | | -) -> List[n_tupel]: |
| 656 | +) -> List[np.ndarray]: # n_tupel |
653 | 657 | """Find correspondences between cameras. |
654 | 658 |
|
655 | 659 | /* correspondences() generates a list of tuple target numbers (one for each |
@@ -686,8 +690,9 @@ def correspondences( |
686 | 690 | nmax = NMAX |
687 | 691 |
|
688 | 692 | # Allocation of scratch buffers for internal tasks and return-value space |
689 | | - con0 = [n_tupel() for _ in range(nmax * cpar.num_cams)] |
690 | | - con = [n_tupel() for _ in range(nmax * cpar.num_cams)] |
| 693 | + con0 = np.empty((nmax * cpar.num_cams,), dtype=n_tupel_dtype) |
| 694 | + con = np.empty((nmax * cpar.num_cams,), dtype=n_tupel_dtype) |
| 695 | + |
691 | 696 | tim = safely_allocate_target_usage_marks(cpar.num_cams, nmax) |
692 | 697 |
|
693 | 698 | # allocate memory for lists of correspondences |
@@ -752,7 +757,7 @@ def correspondences( |
752 | 757 |
|
753 | 758 |
|
754 | 759 | def single_cam_correspondences( |
755 | | - img_pts: List[Target], corrected: List[Coord2d] |
| 760 | + img_pts: List[Target], corrected: np.recarray #List[Coord2d] |
756 | 761 | ) -> Tuple[List[np.ndarray], List[np.ndarray], int]: |
757 | 762 | """ |
758 | 763 | Single camera correspondence is not a real correspondence, it will be only a projection. |
|
0 commit comments