This guide explains how to calibrate the distance-to-focus mapping for the Arducam 64MP Hawkeyes camera used in the MirrorAphrodite smart mirror system.
- Raspberry Pi with the Arducam 64MP Hawkeyes camera connected
- HC-SR04 ultrasonic distance sensor connected to GPIO pins 23 (trigger) and 24 (echo)
- Required Python packages installed (see requirements-calibration.txt)
-
Install system dependencies:
sudo apt update sudo apt install -y python3-picamera2 python3-gpiozero python3-matplotlib python3-numpy
-
Install Python dependencies:
pip install -r requirements-calibration.txt
-
Run the calibration script:
python3 calibrate_focus.py
-
Follow the on-screen instructions to calibrate focus at different distances.
The calibration process involves the following steps:
-
Measure Distance: The script uses the ultrasonic sensor to measure your current distance from the camera.
-
Adjust Focus: You'll interactively adjust the focus value until the image appears perfectly sharp.
-
Save Calibration Point: The distance and optimal focus value are saved as a calibration point.
-
Repeat: Move to different distances and repeat the process to build a comprehensive calibration curve.
-
Generate Mapping: After collecting enough data points, the script can generate the optimal distance-to-focus mapping.
-
Collect Diverse Data Points: Try to collect data points at various distances, especially at:
- Very close range (20-30cm)
- Close range (40-60cm)
- Medium range (70-100cm)
- Far range (110-150cm)
-
Consistent Lighting: Maintain consistent lighting conditions during calibration.
-
Face Position: Keep your face centered in the frame during calibration.
-
Fine Adjustments: Use the fine adjustment mode ('f' key) for precise focus tuning.
-
Verify Results: After calibration, test the generated focus mapping at various distances.
The calibration script produces several outputs:
-
JSON Data File:
focus_calibration.jsoncontains all calibration points. -
Calibration Curve:
focus_calibration_curve.pngshows the relationship between distance and focus. -
Code Snippet:
distance_focus_map_code.txtcontains the code to update in your distance_sensor.py file.
After calibration, copy the generated distance_focus_map from the code snippet into the distance_sensor.py file to update the focus mapping.
- Distance Sensor Issues: Ensure the HC-SR04 sensor is properly connected and not obstructed.
- Camera Issues: Make sure the camera is properly connected and recognized by the system.
- Focus Problems: If focus adjustment doesn't seem to work, restart the script and try again.