Skip to content

Commit

Permalink
Merge pull request #154 from zivid/MISC-2023-04-04-fix-correct-camera…
Browse files Browse the repository at this point in the history
…-in-field

Samples: Fix correct_camera_in_field.py
  • Loading branch information
SatjaSivcev authored Apr 4, 2023
2 parents a421f9b + 9e27065 commit e0f9eaf
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions source/camera/maintenance/correct_camera_in_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
from zivid.experimental import calibration


def _yes_no_prompt(question: str) -> str:
def _yes_no_prompt(question: str) -> bool:
"""Gets a yes or no answer to a given question.
Args:
question: A question what requires a yes or no answer
question: A question that requires a yes or no answer
Returns:
String containing 'y' or 'n'
Bool that is True for 'y' and 'Y' and False for 'n' or 'N'
"""
while True:
response = input(f"{question} (y/n): ")
if response in ["n", "N", "y", "Y"]:
return response.lower()
if response in {"y", "Y"}:
return True
if response in {"n", "N"}:
return False
print("Invalid response. Please respond with either 'y' or 'n'.")


Expand Down Expand Up @@ -84,22 +86,22 @@ def _main() -> None:

# Calculate infield correciton
print(f"Collected {len(dataset)} valid measurements.")
print("Computing new camera correction...")
correction = calibration.compute_camera_correction(dataset)
accuracy_estimate = correction.accuracy_estimate()

print(
"If written to the camera, this correction can be expected to yield a dimension accuracy of ",
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.",
"Accuracy close to where the correction data was collected is likely better.",
)

# Optionally save to camera
answer = _yes_no_prompt("Save to camera? ")
if answer == "y":
print("Writing correction to camera")
calibration.write_camera_correction(camera, correction)
print("Success")
if len(dataset) > 0:
print("Computing new camera correction...")
correction = calibration.compute_camera_correction(dataset)
accuracy_estimate = correction.accuracy_estimate()

print(
"If written to the camera, this correction can be expected to yield a dimension accuracy of ",
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.",
"Accuracy close to where the correction data was collected is likely better.",
)

# Optionally save to camera
if _yes_no_prompt("Save to camera?"):
print("Writing correction to camera")
calibration.write_camera_correction(camera, correction)
print("Success")


if __name__ == "__main__":
Expand Down

0 comments on commit e0f9eaf

Please sign in to comment.