This repository contains two Python scripts for real-time ArUco marker detection and distance estimation using OpenCV. These scripts utilize a webcam to identify ArUco markers, display their IDs, and estimate their position in 3D space relative to the camera.
markerDetection.py
: Detects ArUco markers in real-time and displays their IDs and corner coordinates.distance_estimation.py
: Detects ArUco markers, estimates their 3D position (distance and orientation) using camera calibration data, and displays this information in real-time.
The file MultiMatrix.npz
contains the camera calibration data:
camMatrix
: Camera matrix.distCoef
: Distortion coefficients.rVector
: Rotation vectors.tVector
: Translation vectors.
- Python 3.7+
- OpenCV (
cv2
) - NumPy
- Clone this repository:
git clone https://github.com/PraharshG/Aruco-markers.git cd aruco-detection
- Install the required Python packages:
pip install numpy opencv-python
- Ensure the
MultiMatrix.npz
file and the scripts are in the same directory.
Run markerDetection.py
to detect and identify ArUco markers in the webcam feed.
python markerDetection.py
- Press
q
to exit the video feed. - The script will:
- Detect ArUco markers.
- Draw bounding boxes around detected markers.
- Display the marker ID and corner coordinates in the console.
Run distance_estimation.py
to estimate the distance and position of detected ArUco markers.
python distance_estimation.py
- Press
q
to exit the video feed. - The script will:
- Detect ArUco markers.
- Estimate their 3D position relative to the camera.
- Display the marker ID, distance, and x/y coordinates on the video feed.
ID: [23] [[100, 100], [200, 100], [200, 200], [100, 200]]
- A bounding box will be drawn around the marker with its ID displayed.
ID: [42] Dist: 50.3
x: 10.5 y: -5.2
- Displays the marker's distance and x/y coordinates on the video feed.
You can change the marker dictionary by modifying this line:
marker_dict = aruco.Dictionary_get(aruco.DICT_4X4_100)
Refer to OpenCV's ArUco documentation for more options.
Update the marker_size
variable in distance_estimation.py
to match the physical size of your markers (in centimeters):
marker_size = 10 # centimeters
- Ensure the camera is calibrated using OpenCV to generate the
MultiMatrix.npz
file. Use OpenCV's calibration tutorials if needed. - Lighting conditions and marker quality may affect detection accuracy.