|
19 | 19 | from zivid.experimental import calibration |
20 | 20 |
|
21 | 21 |
|
22 | | -def _yes_no_prompt(question: str) -> str: |
| 22 | +def _yes_no_prompt(question: str) -> bool: |
23 | 23 | """Gets a yes or no answer to a given question. |
24 | 24 |
|
25 | 25 | Args: |
26 | | - question: A question what requires a yes or no answer |
| 26 | + question: A question that requires a yes or no answer |
27 | 27 |
|
28 | 28 | Returns: |
29 | | - String containing 'y' or 'n' |
| 29 | + Bool that is True for 'y' and 'Y' and False for 'n' or 'N' |
30 | 30 |
|
31 | 31 | """ |
32 | 32 | while True: |
33 | 33 | response = input(f"{question} (y/n): ") |
34 | | - if response in ["n", "N", "y", "Y"]: |
35 | | - return response.lower() |
| 34 | + if response in {"y", "Y"}: |
| 35 | + return True |
| 36 | + if response in {"n", "N"}: |
| 37 | + return False |
36 | 38 | print("Invalid response. Please respond with either 'y' or 'n'.") |
37 | 39 |
|
38 | 40 |
|
@@ -84,22 +86,22 @@ def _main() -> None: |
84 | 86 |
|
85 | 87 | # Calculate infield correciton |
86 | 88 | print(f"Collected {len(dataset)} valid measurements.") |
87 | | - print("Computing new camera correction...") |
88 | | - correction = calibration.compute_camera_correction(dataset) |
89 | | - accuracy_estimate = correction.accuracy_estimate() |
90 | | - |
91 | | - print( |
92 | | - "If written to the camera, this correction can be expected to yield a dimension accuracy of ", |
93 | | - f"{accuracy_estimate.dimension_accuracy()*100:.3f} or better in the range of z=[{accuracy_estimate.z_min():.3f}, {accuracy_estimate.z_max():.3f}] across the full FOV.", |
94 | | - "Accuracy close to where the correction data was collected is likely better.", |
95 | | - ) |
96 | | - |
97 | | - # Optionally save to camera |
98 | | - answer = _yes_no_prompt("Save to camera? ") |
99 | | - if answer == "y": |
100 | | - print("Writing correction to camera") |
101 | | - calibration.write_camera_correction(camera, correction) |
102 | | - print("Success") |
| 89 | + if len(dataset) > 0: |
| 90 | + print("Computing new camera correction...") |
| 91 | + correction = calibration.compute_camera_correction(dataset) |
| 92 | + accuracy_estimate = correction.accuracy_estimate() |
| 93 | + |
| 94 | + print( |
| 95 | + "If written to the camera, this correction can be expected to yield a dimension accuracy of ", |
| 96 | + f"{accuracy_estimate.dimension_accuracy()*100:.3f} or better in the range of z=[{accuracy_estimate.z_min():.3f}, {accuracy_estimate.z_max():.3f}] across the full FOV.", |
| 97 | + "Accuracy close to where the correction data was collected is likely better.", |
| 98 | + ) |
| 99 | + |
| 100 | + # Optionally save to camera |
| 101 | + if _yes_no_prompt("Save to camera?"): |
| 102 | + print("Writing correction to camera") |
| 103 | + calibration.write_camera_correction(camera, correction) |
| 104 | + print("Success") |
103 | 105 |
|
104 | 106 |
|
105 | 107 | if __name__ == "__main__": |
|
0 commit comments