Intel RealSense D435 + OpenCV (Python) Installation Guide

Update 12/5/2019: It seems like this tutorial is getting quite a bit of traffic now- I’d just like to add that apparently this guide still works for Python 3. I haven’t tried it myself but hope that helps!

Date posted: 10/24/2018, Date written: 8/8/2018

I wrote this how-to guide during my internship at P&G (May-August 2018). At the time, there wasn’t that much documentation on the newly released Python wrapper for the Intel RealSense SDK, so it was a challenge to get everything to work. I believe there is a new version of OpenCV out right now, and I’m well aware that this guide may get outdated quickly (given how fast things change), but I hope it’s still helpful. I broke it down into several different sections- this is the page that will link them all together and focus specifically on the installation of Pyrealsense 2.0 (Python wrapper) and the RealSense SDK. Also, this guide is catered towards a beginner, so more advanced users may find some screenshots/steps unnecessary.

For getting started with computer vision, I whole-heartedly recommend the excellent tutorials on PyImageSearch.com. Be on the lookout for future guides combining his tutorials with the RealSense camera on my website too!

WINDOWS ONLY

Versions at time of writing:

·       Intel RealSense D435 Camera

·       Python 2.7.15

·       OpenCV 3.4.2 + OpenCV Contrib

·       Intel RealSense SDK 2.0

·       Pyrealsense 2.0 (Python wrapper)

·       Numpy 1.15.0

·       Pandas 0.23.3

·       Windows Visual Studio IDE 2017 Community

You should follow the tutorials in this order:

  1. Python 2.7 Installation

  2. Intel RealSense SDK 2.0 + Pyrealsense 2.0 Installation: Part I

  3. OpenCV 3.4 Installation

  4. Intel RealSense SDK 2.0 + Pyrealsense 2.0 Installation: Part II

  5. Pip Installation + Basic Powershell Navigation

  6. Numpy, Pandas, Cython, Imutils Installation

    • Numpy: Highly recommended for use with OpenCV

    • Pandas: Optional but highly recommended if collecting data

    • Cython: Might be required

    • Imutils: Optional but recommended if using PyImageSearch.com tutorials

2) Intel Realsense SDK 2.0 + Pyrealsense 2.0 Installation: Part I

1. Go to https://github.com/IntelRealSense/librealsense/releases and download the source code (.zip). You can download the other applications (.exe) too, but they’re not required for programming with the camera. They’re pretty cool and user-friendly though.

8.png

2. Download CMake from https://cmake.org/download/. Select the correct MSI file for your system architecture.

9.png

3. Download Windows Visual Studio IDE 2017 Community Version: https://visualstudio.microsoft.com/ . Make sure you download the C++ and Python development extensions.

4. Unzip the RealSenseSDK and rename it to something easier to find, like “librealsense”. I downloaded it directly from the Github repository, so my file names may be slightly different in screenshots, but it should be the same process. Make a new folder in the home directory named “build”.

10.png

We will get back to installing the SDK after installing OpenCV! Please go to the OpenCV 3.4 Installation Guide.

4) Intel RealSense SDK 2.0 + Pyrealsense 2.0 Installation: Part II

1. Open CMake GUI and select the source to be the folder that the RealSense SDK is in, and the build to be the build folder you made at the end of Part I.

2. Click configure and check the following options:

BUILD_CV_EXAMPLES

BUILD_EXAMPLES

BUILD_PYTHON_BINDINGS

Set OpenCV_Dir to the build folder for OpenCV from the previous tutorial.

16.png

3. Click Generate, using Visual Studio 2017 as your generator. Click Open Project and the build the solution by pressing Ctrl+Shift+B. You can explore and run the examples in Visual Studio by selecting the program and pressing F5.

4. Copy and paste pyrealsense2.pyd and realsense2.dll from the Librealsense folder into C:\Python27\Lib\site-packages.

5. You can check if Pyrealsense was installed correctly by using the Powershell again. Open the Python environment and type “import pyrealsense2”- if there are no errors, you’re good. If there is, exit the Python environment (“exit()”) and type “pip install pyrealsense2”. Repeat step 4, but look for those files in the Pyrealsense folder. Check the installation again by importing Pyrealsense2 in the Python environment in the Powershell. If you run into errors with pip, then continue to the Pip Installation section. If you run into errors with Cython, go to the Cython tutorial.

17.png

Make sure to finish up the other tutorials:

Pip Installation + Basic Powershell Navigation

Numpy, Pandas, Cython, Imutils Installation

And that’s it! I think in the future I might also post a tutorial about how to use PyImageSearch.com’s computer vision guides with the Intel RealSense camera, so be on the lookout for that as well.