Skip to content

Commit e0f9eaf

Browse files
authored
Merge pull request #154 from zivid/MISC-2023-04-04-fix-correct-camera-in-field
Samples: Fix correct_camera_in_field.py
2 parents a421f9b + 9e27065 commit e0f9eaf

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

source/camera/maintenance/correct_camera_in_field.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@
1919
from zivid.experimental import calibration
2020

2121

22-
def _yes_no_prompt(question: str) -> str:
22+
def _yes_no_prompt(question: str) -> bool:
2323
"""Gets a yes or no answer to a given question.
2424
2525
Args:
26-
question: A question what requires a yes or no answer
26+
question: A question that requires a yes or no answer
2727
2828
Returns:
29-
String containing 'y' or 'n'
29+
Bool that is True for 'y' and 'Y' and False for 'n' or 'N'
3030
3131
"""
3232
while True:
3333
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
3638
print("Invalid response. Please respond with either 'y' or 'n'.")
3739

3840

@@ -84,22 +86,22 @@ def _main() -> None:
8486

8587
# Calculate infield correciton
8688
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")
103105

104106

105107
if __name__ == "__main__":

0 commit comments

Comments
 (0)