.. _python_example:

Python Example
==============

This example demonstrates how to use the ``epc_tofcam_native`` Python module to capture
and visualize DCS, amplitude and distance frames from the EPC670 ToF camera using matplotlib.

.. image:: ../_static/images/python_example_screenshot.png
   :alt: python example result
   :align: center
   :width: 60%

Prerequisites
-------------

- A connected EPC670 ToF camera module
- The ``epc_tofcam_native`` Python package installed
- ``matplotlib`` installed:

.. code-block:: bash

   pip install matplotlib epc-tofcam-native

Run
---

.. code-block:: bash

   python3 python_example.py

A matplotlib window will open showing the amplitude and distance images of a single
captured frame.

How It Works
------------

1. **Open** the camera with ``cam.open()``.
2. **Configure** the exposure time and modulation frequency via ``cam.setControl()``.
3. **Start the stream** with ``cam.startStream()`` to enable continuous frame acquisition.
4. **Capture a single frame** with ``cam.captureFrame()`` and extract the DCS, amplitude and
   distance data using ``frame.get()``.
5. **Stop the stream** with ``cam.stopStream()`` and close the connection with ``cam.close()``.
6. The captured data is displayed in a **matplotlib figure** with all four DCS images on the
   top row and amplitude and distance images on the bottom.


Full Source Code
----------------

.. literalinclude:: ../../../samples/python_examples/src/python_example.py
   :language: python
   :linenos: