Point a webcam at a printed ArUco marker and:
objects/cube.obj, rendered with OpenGLNeeds Python 3.9 or newer and a webcam. Run one script; on the first run it creates a psdenv virtual
environment and installs the requirements, then opens the menu:
Windows:
.\run.bat
or.\run.ps1Linux/macOS:
./run.shThen:
arucoMarkers/DICT_5X5_100_1.png so the black square is
5 cm wide (or pass --marker-length with your size). Keep the white border.| Demo | Script | |
|---|---|---|
| 1 | Generate a printable marker | scripts/generate_aruco.py |
| 2 | ArUco detection | scripts/aruco_detection.py |
| 3 | Pose estimation: axes and distance | scripts/pose_estimation.py |
| 4 | 3D OBJ model on the marker (OpenGL) | scripts/pose_obj_object.py |
| 5 | Depth-aware AR with occlusion | scripts/ar_depth.py |
| 6 | Object tracking with YOLOv5 (optional) | scripts/object_tracking.py |
Every demo can also be run on its own, and accepts an image or video instead of the webcam:
python scripts/ar_depth.py # webcam
python scripts/ar_depth.py --image photo.jpg
python scripts/ar_depth.py --video clip.mp4 --save out.mp4
python scripts/pose_estimation.py --dict DICT_4X4_50 --marker-length 0.08
python scripts/generate_aruco.py --id 7 --size 600
Common options: --image, --video, --camera N, --dict, --marker-length (metres), --save, --no-show.
Run any script with --help for the full list.
scripts/ar_depth.py stands a cube on the marker and hides the parts of it that are behind real objects.
Keys: o turns occlusion on and off, d shows the depth map, q / Esc quits.
models/ on first use. --model large is more detailed but about
20× slower on a CPU.--tolerance sets how much closer a surface must be to hide the cube.Without calibration the demos assume a typical webcam (about 60° field of view, no lens distortion). The cube
still sits on the marker, but distances are approximate. For accurate poses, save your camera’s calibration as
calibration.npz in the repo folder:
import numpy as np
np.savez("calibration.npz", camera_matrix=K, dist_coeffs=dist, image_size=[width, height])
(K and dist come from cv2.calibrateCamera; see OpenCV’s
calibration tutorial.)
python -m venv psdenv
psdenv\Scripts\activate # Linux/macOS: source psdenv/bin/activate
pip install -r requirements.txt
python main.py
Install opencv-contrib-python only, not opencv-python as well: the two packages overwrite each other’s
cv2 module. The code uses the ArUco API from OpenCV 4.7 and newer (ArucoDetector, generateImageMarker,
solvePnP); the older Dictionary_get / detectMarkers / estimatePoseSingleMarkers functions no longer exist.
Object tracking (menu 6) needs extra, large packages (about 2.5 GB):
pip install torch deep-sort-realtime
main.py Menu
requirements.txt
run.bat, run.ps1, run.sh Create the venv, install requirements, start the menu
scripts/
ar_common.py ArUco detection, pose (solvePnP), camera intrinsics, webcam/image/video loop
generate_aruco.py Printable markers
aruco_detection.py Detection
pose_estimation.py Pose axes and distance
pose_obj_object.py OBJ model with OpenGL + pygame
ar_depth.py Depth-aware AR with occlusion
depth.py MiDaS depth (ONNX) and metric scaling
object_tracking.py YOLOv5 + DeepSORT tracking (optional)
pose_object.py, glyph*.py, webcam.py, constants.py Older glyph-marker version (not maintained; needs
cube_0-3.obj files that are not in the repo)
objects/ cube.obj, material and texture