Augmented reality card based application with Python
, numpy
and OpenCV
.
- Place the image of the surface to be tracked inside the
reference
folder. - On line 16 of
ar_main.py
replace the first argument to the classAR_3D
with the name of the image you just copied inside thereference
folder (note: at the moment the extension is assumed to be.jpg
). - The 3D object to render is chosen as user input argument (see next section), by default it is rendered the first
.obj
file in themodels
folder. To change the size of the rendered model change the scale parameter (number3
) in line 164 ofsrc/aaugmented_reality_3D.py
by a suitable number. This might require some trial and error. - Open a terminal session inside the project folder and run
python ar_main.py
Check the input argument help, type:
python ar_main.py -h
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.
The code as been tested in python 3.7.4
but I suppose any 3.x
version should work. The only required package should be: cv2 (openCV), numpy.
To check the python notebook install jupiter or jupiter lab.
Another way is to install all the required package via:
pip install -r requirements.txt
which lists all the packages, also those required and installed together with cv2 and numpy but also some additional packages (e.g. some linting packages) that maybe you don't want.
Remark: check this guide to understand how I created a dedicated virtual environment for this project.
Check the python notebook in the notebook
folder or read the blog entries for an in-depth explanation of the logic behind the code: