This repository contains exercises for the course "Grafische Datenverarbeitung" at HS Furtwangen University. Please note that all content here is tentative and will be adapted to the student's needs during the semester.
First, we need to download and install Python 3 from python.org. The recommended
version is 3.10.7
or above. Then, we can use the following terminal command to inspect the currently installed
version:
Windows | MacOS |
---|---|
python --version |
python3 --version |
Ensure that the terminal and selected interpreter use the correct version.
Usually, the Python installation includes the dependency management tool pip out of the box. If not, download and
install it from pip.pypa.io. The minimum required version is 19.3
and
above. We can again use a terminal command to check the version:
Windows | MacOS |
---|---|
pip --version |
python3 -m pip --version |
If you need to update your pip version use
python -m pip install --upgrade pip
Do not forget to use python3
instead of python
on MacOS.
A great selection of useful resources are:
- https://www.python.org/about/gettingstarted/
- https://docs.python.org/3/tutorial/
- https://code.visualstudio.com/docs/python/python-tutorial
Generally, one can use any code editor or IDE to follow these exercises, but we recommend that students use VS Code. You
can download VS Code from https://code.visualstudio.com/. On Linux, you can follow the instructions on
this page. On Arch-based systems, you can use the OSS version code
(Link) or the fully
featured proprietary version visual-studio-code-bin
(Link) from AUR.
- Python
ms-python.python
: Python support in VS Code (Link) - Pylance
ms-python.vscode-pylance
: Python language server (Link) - Python Image Preview
076923.python-image-preview
: you can quickly check your Python image data during debugging (Link) - Todo Tree
Gruntfuggly.todo-tree
: provides an overview of all code lines marked with "TODO" (Link)
To more easily develop Python code, it is recommended to set up a virtual environment (VENV) in the project root folder.
The following terminal command will create the hidden folder .venv
in your current project folder:
python -m venv .venv
Do not forget to use python3
instead of python
on MacOS.
Next, we need to enable the VENV. The VENV will only be active for the current terminal session. Closing the terminal and re-opening it will disable the VENV. So always make sure to enable it before you start developing.
# For Windows use
.venv\Scripts\Activate.ps1
# For Linux and Mac OS
source .venv/bin/activate
Special care is needed when using Windows. Please consult the following guide for more information. When the environment is activated, you should see this as a prefix on your terminal.
On both Operation Systems, one can deactivate the VENV with the following terminal command:
deactivate
Installing the required dependencies is straightforward:
pip install .
This will load the defined dependencies in pyproject.toml
and install them inside the VENV. Note that the ultralytics module needed for the last tutorials is excluded, as this sums up to more than one Gigabyte of data as some machine learning modules are included (e.g. torch).
If you want to install it later use:
pip install ultralytics
Now you are ready to start working on the exercises. The tutorials/src
folder contains all the code. The idea is to start with the
<XX>-<NAME>.problem.py
files and try to fulfill the TODOs. These "problem" files will guide you in the right
direction. You can ask for help during the lecture if there are any questions. Next, the <XX>-<NAME>.solution.py
files
contain the solution. After you implement your solution, use this file to compare and add some improvements to your
code.
You can use https://docs.python.org/3/ as a starting point, and the Library Reference or the Language Reference should contain all the needed information.
See https://docs.opencv.org/4.x/ for the OpenCV code reference. Here, all OpenCV methods are explained. If you want to know about parameters and flags, this is the page to look them up.
OpenCV uses NumPy ndarrays
as the default format for data exchange. It can create, operate on, and work with NumPy
arrays. For some operations, import the NumPy module and use special functions provided by NumPy. Other libraries like
TensorFlow and SciPy also use NumPy. See the official docs for the API reference.