A Python project that brings augmented reality to life by overlaying 3D objects on Aruco markers using OpenCV and OpenGL.
- Python 3.x
- OpenCV 3.x (
opencv_contribrequired for Aruco support) - imutils
- PyYAML
- pygame
- PyOpenGL
Install Python packages via pip:
pip install imutils pyyaml pygame PyOpenGLDeveloped and tested on Anaconda 4 (Python 3.x, Windows 10), but should work on most platforms.
main.py: Main code. Loads the 3D object, initializes your camera, detects Aruco markers, and overlays the 3D object.objloader.py: Utility for loading OBJ files (see PyGame Wiki)..objand.mtlfiles: Your 3D model (exported from Blender or other 3D software). Both are required for proper rendering.
-
Camera Calibration
- Calibrate your camera first. Use scripts in the
calibrationdirectory (see details below). - This generates a
.yamlfile for your camera matrix.
- Calibrate your camera first. Use scripts in the
-
Prepare Your Files
- Place your
camera_matrix.yaml,.obj, and.mtlfiles in the project’s main directory.
- Place your
-
Run the Demo
python main.py
You can calibrate using either a chessboard or an Aruco board.
-
Edit
calibration/main.py:- Set your video source (camera index or file).
- Set output YAML filename.
-
Run and follow the instructions.
-
When done, copy the generated YAML to the main directory.
-
Edit
calibration/aruco.py:- Set your video source and output YAML filename.
-
Run the script.
-
Move or rename the generated YAML file to match the main directory config.
- Download
.objmodels with matching.mtlfiles (e.g., from Free3D). - Replace the
.objand.mtlfiles in your main directory. - Without an
.mtlfile, objects will render black. - You can create/edit models in Blender or other 3D tools.
- OpenGL window lighting may be dimmer than OpenCV—work in a well-lit room.
- All required files (
main.py,objloader.py, model files,camera_matrix.yaml) must be in the same folder. - Report bugs or issues by opening an issue or reaching out.
- 3D models included are not owned by me. See the license/readme in
models/orzip/sinband/for details.
- University of Cordoba: Aruco Documentation
- Augmented Reality using OpenCV, OpenGL, and Blender
- JeVois Aruco Demo