Augmented Reality with OpenCV using Python.
- Place the image of the surface to be tracked inside the
references
folder; - Replace
TRAIN_IMAGE_RELATIVE_PATH
with the relative path of the train image you want to track; - Replace
OBJ_MODEL_RELATIVE_PATH
with the relative path of the model you want to render. To change the size of the rendered model change the scale parameterMODEL_OBJ_SCALE
to a suitable number. This might require some trial and error.
Open a terminal session inside the project folder and run:
# Activate virtualenv
virtualenv python_ra
source python_ra/bin/activate
# to deactivate: run `deactivate`
Then:
# Install from the requirements
pip install -r requirements.txt
python3 src/ra.py
--rectangle
,-r
: Draws the projection of the reference surface on the video frame as a blue rectangle;--matches
,-ma
: Draws matches between reference surface and video frame.
python3 src/ra.py -r -ma
If you get the message:
Unable to capture video
printed to your terminal, the most likely cause is that your OpenCV installation has been compiled without FFMPEG support. Pre-built OpenCV packages such as the ones downloaded via pip are not compiled with FFMPEG support, which means that you have to build it manually.