[Mac] Run the RealSense D415 sample in Python

What is RealSense D415?

Realsense provided by Intel is a camera device with a depth perception function. It doesn't officially support mac, but it can be run with an unofficial library called librealsense.

environment

Environment construction procedure

Install the required libraries

Open a terminal and execute the following command line by line in your home directory

Terminal


$ brew install python
$ brew install libusb pkg-config
$ brew install homebrew/core/glfw3
$ brew install cmake
$ brew install boost
$ brew install flann
$ brew install vtk5 –with-qt
$ git clone https://github.com/PointCloudLibrary/pcl
$ cd pcl
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install

Install & build librealsense source code

Return to your home directory with the cd command and install the main body of librealsense. Replace the absolute path of Python you are using on the third line with the path output by which python.

Terminal


$ git clone https://github.com/IntelRealSense/librealsense.git
$ cd librealsense
$ mkdir build && cd build
$ cmake .. -DBUILD_EXAMPLES=true -DBUILD_WITH_OPENMP=false -DHWM_OVER_XU=false -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE:FILEPATH=Absolute path of Pyhton you are using-G "Unix Makefiles"
$ make -j2
$ sudo make install

In my environment, the Python version did not work on 3.8 series, so change the version to 3.6 series in advance (this time I will use python 3.6.7) Return to the / libresense directory

Terminal


$ pyenv install 3.6.7
$ pyenv local 3.6.7

Use the pyenv versions command to check that the area under the/libresense directory is python3.6.7. Also, I think that it will not work as it is, so check the location where the so file is stored (hereinafter A) by the following procedure.

  1. Open librealsense/build/CMakeCache.txt with VS Code etc.
  2. Open the search window with command + F and search for PYTHON_INSTALL_DIR: PATH
  3. The directory where .xxx, which says PYTHON_INSTALL_DIR: PATH: PATH = xxx, is the so file (A)

Check where to put the symbolic (B)

Terminal


$ python3
>>>import site; site.getsitepackages()

After that, move to the confirmed location (B) and create a symbolic

Terminal


$Absolute path to cd B
$ ln -s Confirmed so file path(A)/pyrealsense2.cpython-36m-darwin.so pyrealsense2.so
$ ln -s Confirmed so file path(A)/pybackend2.cpython-36m-darwin.so pybackend2.so

Check if the import of pyrealsense2 passes

Terminal


$ python
>>> import pyrealsense2
>>>

If import passes like this, it's OK

Move the sample

Connect mac and Realsense via USB, move to the directory where the sample files are located, and execute

Terminal


$ cd ~/librealsense/wrappers/python/examples
$python File name you want to run

reference (Reference Qiita1) [https://qiita.com/mizumasa/items/c6ca2c73fa86c9a5a39c]

(Reference Qiita2) [https://qiita.com/comachi/items/14b358568365bc5ee474]

Recommended Posts

[Mac] Run the RealSense D415 sample in Python
Until you run the changefinder sample in python
Download the file in Python
Run automatic jobs in python
Find the difference in Python
Run shell commands in python
Run Python unittests in parallel
[Python] Insert ":" in MAC address
Solve ABC175 D in Python
After enabling the python virtual environment in the batch file, run the python file
Python in the browser: Brython's recommendation
Let's run "python -m antigravity" in python
Save the binary file in Python
AtCoder: Python: Daddy the sample test.
Hit the Sesami API in Python
Run shell command / python in R
Get the desktop path in Python
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Hit the web API in Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
Run unittests in Python (for beginners)
Get the host name in Python
Run a simple algorithm in Python
Access the Twitter API in Python
The first step in Python Matplotlib
I wrote the stack in Python
Master the weakref module in Python
Try running the basic information Python sample problem only in the browser
The story that 2D list replacement did not work in python
Solve the smallest value in Python (equivalent to paiza rank D)
Learn the design pattern "Prototype" in Python
Learn the design pattern "Builder" in Python
[Python, Julia] 3D display in Jupyter-Mayavi library
Try using the Wunderlist API in Python
Specify the color in the matplotlib 2D map
Check the behavior of destructor in Python
Learn the design pattern "Flyweight" in Python
Try using the Kraken API in Python
Learn the design pattern "Observer" in Python
Learn the design pattern "Memento" in Python
Learn the design pattern "Proxy" in Python
Write the test in a python docstring
ABC 157 D --Solve Friend Suggestions in Python!
Learn the design pattern "Command" in Python
OR the List in Python (zip function)
Sample script to trap signals in Python
Display Python 3 in the browser with MAMP
Tweet using the Twitter API in Python
Run AzureKinect in Python on Christmas Eve.
Learn the design pattern "Bridge" in Python
Check if the URL exists in Python
Learn the design pattern "Mediator" in Python
Associate the table set in python models.py
The result of installing python in Anaconda
What is "mahjong" in the Python library? ??
Read the file line by line in Python