# ToF Minimal

This example shows a minimal ToF pipeline and visualizes depth with a colormap.For architecture and settings, see the [ToF node
docs](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/tof.md).

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Pipeline

Pipeline nodes:
- ToF(0)
- XLinkOut (1)

Pipeline connections:
- ToF(0) -> XLinkOut (1) (depth -> in)

## Source code

#### Python

```python
#!/usr/bin/env python3
"""Minimal ToF script showing the main output stream.

Displays depth.
For more streams, see tof_all_queues.py.

Press 'q' to quit.
"""

import cv2
import depthai as dai

FPS = 30.0

def main():
    pipeline = dai.Pipeline()

    minDepth = 100.0
    maxDepth = 7000.0

    profile = dai.ToFConfig.Profile.MID_RANGE

    tof = pipeline.create(dai.node.ToF).build(
        boardSocket=dai.CameraBoardSocket.AUTO,
        profile=profile,
        fps=FPS,
    )

    depthOutputQueue = tof.depth.createOutputQueue()

    with pipeline as p:
        p.start()
        while p.isRunning():
            depth = depthOutputQueue.get()
            cv2.imshow("depth", dai.utility.colorizeDepthFrame(depth, minDepth, maxDepth, useLog=True).getCvFrame())

            if cv2.waitKey(1) == ord("q"):
                break

if __name__ == "__main__":
    main()
```

#### C++

```cpp
#include <opencv2/opencv.hpp>

#include "depthai/depthai.hpp"

constexpr float FPS = 30.0f;
int main() {
    auto device = std::make_shared<dai::Device>();
    dai::Pipeline pipeline(device);

    constexpr float minDepth = 100.0f;
    constexpr float maxDepth = 7000.0f;

    auto profile = dai::ToFConfig::Profile::MID_RANGE;

    auto tof = pipeline.create<dai::node::ToF>()->build(dai::CameraBoardSocket::AUTO, profile, FPS);

    auto depthOutputQueue = tof->depth.createOutputQueue();

    pipeline.start();
    while(pipeline.isRunning()) {
        auto depth = depthOutputQueue->get<dai::ImgFrame>();
        cv::imshow("depth", dai::utility::colorizeDepthFrame(*depth, minDepth, maxDepth, cv::COLORMAP_JET, true).getCvFrame());

        if(cv::waitKey(1) == 'q') {
            break;
        }
    }

    return 0;
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
