Python Quickstart

Overview

Mirrorcle’s Python API is wrapped from C++ to Python using the Simplified Wrapper and Interface Generator (SWIG).

This means that all classes, structs, and methods that are available in Mirrorcle’s C++ library are also available in Python!

The key difference is that the Python API uses NumPy for handling arrays instead of C-style arrays and pointers.

Prerequisites

For Windows users:

Mirrorcle’s Python SDK for Windows requires a 32-bit build of Python.

Ensure that you have installed 32 bit Python 3 to your system and have added Python to your Environment Variables -> Path

This can be checked by running the below line in your Command Prompt

python -V -V

Which should return a Python version greater than 3.x.x, and a 32 bit target build system.

For Linux users:

The provided Raspberry Pi comes with both Python 2 and Python 3 installed. To differentiate use python3 to specify Python 3

python3 MTIDevice-Demo.py

Note

Debug versions of Python require that the mtidevice/_MTIDevice.pyd file be copied and renamed to _MTIDevice_d.pyd, otherwise Python will not be able to find and load the _MTIDevice.pyd library.

Running the Provided Demos

Mirrorcle’s Python SDK comes as a folder labeled “SDK-Python” which includes four demos:

MTIDevice-Demo.py
  • Python translation of the C++ MTIDevice-Demo, showcases multiple drive methodologies

TrackingExamples.py
  • For owners of the DEMO-01, demonstrates mutliple approaches tracking using MEMS mirrors

RGBExamples.py
  • Demonstrates interaction with RGB Controllers for multi-color vector display

GenerateTextData-Demo.py
  • A unique Python demo that demonstrates the versatility of the Mirrorcle API when paired with the Python language

Demo-Template.py
  • A template for users to write their own demos. The template handles connection, loading parameters, and disconnecting.

In order to run the demos, navigate to the SDK-Python folder using your shell (command prompt on Windows, terminal on Linux) or IDE of choice.

For Windows users:

python MTIDevice-Demo.py

For Linux users:

python3 MTIDevice-Demo.py

Installing the mtidevice Module

For Windows users, the folder contains a setup.py file to allow for installation of the mtidevice module to your Python site-packages.

To install to your Python installation’s site-packages, run the following:

python setup.py install

For Linux users and as an alternative for Windows users, the Mirrorcle Python package “mtidevice” can be integrated in your project by placing the “mtidevice” folder in your project’s folder (i.e. in the same folder as your source.py).

Then see the “Importing the Module” section below.

Dependencies

Note

Linux users should not need to install any packages or dependencies.

Mirrorcle’s Python API requires only NumPy, which will be installed automatically upon python setup.py install

To run the examples, OpenCV-Python and freetype-py is required.

These will also be downloaded upon running the setup.py.

Additionally, these packages can be installed using pip (Python package installer):

Windows

python -m pip install numpy
python -m pip install opencv-python
python -m pip install freetype-py

Linux

pip3 install numpy
pip3 install opencv-python
pip3 install freetype-py

The script InstallDependencies.py is provided to quickly install these three Python modules via pip, and can be run from the command prompt/terminal:

python InstallDependencies.py

Importing the Module

Independent of the chosen installation method.

import mtidevice
from mtidevice import MTIError, MTIAxes, MTIParam, MTIDataMode, MTISync, MTIDataFormat