---
title: "range-filter"
description: "## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#overview](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#overview)Overview Since depth camera can measure the distance for each pixel. We can easily build a range filter, focusing of specific distance of data that we want are interesting in. ## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#expect-output](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#expect-output)Expect Output ![rf1 | LIPS® Developer Documentation](https://dev.lips-hci.com/wp-content/uploads/2025/02/rf1.avif) ##…"
url: "https://dev.lips-hci.com/lipsedge-sdk-c/range-filter/"
updated: "2025-09-05"
category: "LIPSedge™ SDK 1.x / LIPSedge™ SDK Languages & Libraries / C++"
tags:
  - LIPSedge SDK
---

# range-filter

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#overview](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#overview)Overview

Since depth camera can measure the distance for each pixel. We can easily build a range filter, focusing of specific distance of data that we want are interesting in.

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#expect-output](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#expect-output)Expect Output

![rf1 | LIPS® Developer Documentation](https://dev.lips-hci.com/wp-content/uploads/2025/02/rf1.avif)

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#prerequisite](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#prerequisite)Prerequisite

- [OpenCV Viewer](https://dev.lips-hci.com/lipsedge-sdk-c/opencv-viewer/)

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#tutorial](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#tutorial)Tutorial

Modify from [opencv_viewer](https://dev.lips-hci.com/lipsedge-sdk-c/opencv-viewer/). After getting color and depth frame, we use opencv `threshold` function to filter out distance less than `threasholdValueDown` and greater than `thresholdValueUp`.

The distance units used by the SDK vary depending on the camera. In this example, we use the LIPSEdge L215 camera, which uses millimeters (mm) as the unit. So, here we set the distance limit from 500mm to 1500mm.

```
double thresholdValueUp = 1500;
double thresholdValueDown = 500;

...

cv::threshold(thres, thres, thresholdValueDown, 1024, cv::THRESH_TOZERO);
cv::threshold(thres, thres, thresholdValueUp, 1024, cv::THRESH_TOZERO_INV);
```

Then we do the threshold again, to convert all the remaining depth value to 1, and the other value to 0. This create a region of interest (white area) base on distance.

```
cv::threshold(thres, thres, 1, 1024, cv::THRESH_BINARY_INV);
```

Finally, convert `depth` and `thres` to gray scale value then display all of it

````
depthMat.convertTo(depthMat, CV_8UC1, 255.0 / 1024.0);
thres.convertTo(thres, CV_8UC1, 255.0 / 1024.0);

cv::imshow("Color", colorMat);
cv::imshow("Depth", depthMat);
cv::imshow("Threshold", thres);
        ```
````

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#full-code](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview/range-filter#full-code)Full code

[range-filter](https://github.com/lips-hci/dev-doc-code-samples/blob/master/c%2B%2B/range-filter/range-filter.cpp)
