Python (Ubuntu)

This topic introduces how to obtain and run the Mech-Eye API Python samples on Ubuntu.

Sample List

The following samples are currently provided:

  • trigger_with_software_and_fixed_rate: Trigger data acquisition with the software + fixed rate method, and then retrieve and save the acquired data.

  • trigger_with_external_device_and_fixed_rate: Trigger data acquisition with the external + fixed rate method, and then retrieve and save the acquired data.

  • trigger_with_software_and_encoder: Trigger data acquisition with the software + encoder method, and then retrieve and save the acquired data.

  • trigger_with_external_device_and_encoder: Trigger data acquisition with the external + encoder method, and then retrieve and save the acquired data.

  • trigger_multiple_profilers_simultaneously: Trigger multiple laser profilers to acquire data asynchronously, and then retrieve and save the acquired data.

  • blind_spot_filtering: Detect and remove the false data caused by blind spots and obtain the filtered profile data.

  • noise_removal: Remove the noise in the depth data and obtain the filtered profile data.

  • profile_alignment: Correct the X-axis and Z-axis vibrations in the profiles (aligning the profiles) and obtain the corrected profile data.

  • render_depth_map: Obtain and save the depth map rendered with the jet color scheme.

  • transform_point_cloud: Obtain and save the point clouds in the custom reference frame.

  • manage_user_sets: Manage parameter groups, such as obtaining the names of all parameter groups, adding a parameter group, switching the parameter group, and saving parameter settings to the parameter group.

  • print_profiler_status: Obtain and print the laser profiler’s information, such as model, serial number, firmware version, and temperatures.

  • register_profiler_event: Define and Register the callback function for monitoring laser profiler events.

  • use_virtual_device: Acquire the profile data stored in a virtual device, generate the intensity image and depth map, and save the images.

For different methods of triggering the laser profiler to acquire data, refer to Methods for Triggering Data Acquisition.

Prerequisites

In order to use the Python samples of Mech-Eye API, the following prerequisites must be satisfied:

  • Connect the laser profiler and computer correctly.

  • Make sure that the variant of Python installed is 64-bit, and that the version is between 3.7 and 3.11.

  • Obtain the samples.

  • Install the required software.

  • (Optional) Install software libraries on which the samples depend.

Obtain Samples

Python samples are included in the installation path of Mech-Eye SDK or can be obtained from GitHub by cloning. The samples in the installation path are the version at the time of Mech-Eye SDK release. The version on GitHub may contain the latest changes.

  • The samples in the installation directory are located in /opt/mech-mind/mech-eye-sdk/samples/python/profiler.

  • The samples cloned from GitHub are located in xxx/mecheye_python_samples/profiler.

Execute the following command to clone the Python samples from GitHub:

cd ~
git clone https://github.com/MechMindRobotics/mecheye_python_samples.git

Install Required Software

In order to use the Python samples of Mech-Eye API, dependency libraries, Mech-Eye SDK, and Python Mech-Eye API must be installed.

  1. Install Mech-Eye SDK: Please refer to Mech-Eye SDK Installation Guide (Ubuntu).

  2. Install pip3 or upgrade pip3 to ensure its version is 20.3.1 or above.

    Instructions
    • Execute the following command to check if pip3 is installed and its version:

      pip3 -V
    • Execute the following command to install pip3:

      sudo apt install python3-pip
    • Execute the following command to upgrade pip3:

      python3 -m pip install --upgrade pip
  3. Upgrade g++ to ensure that its version is 12 or above.

    If the g++ version is lower than 12, import will fail.
    Instructions
    1. Execute the following command to install a later version g++ (using g++ 13 as an example):

      sudo add-apt-repository ppa:ubuntu-toolchain-r/test
      sudo apt-get update
      sudo apt install g++-13
    2. Use the ls command to check the installed versions of g++:

      ls /usr/bin/g++*
    3. Execute the following command to add all installed versions of g++ as alternatives (using g++ 9 and g++ 13 as examples):

      The number at the end of the command is priority. The larger the number, the higher the priority.
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 10
      sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 20
    4. Execute the following command to select the g++ version. Enter the number corresponding to the later version g++ to select this version.

      sudo update-alternatives --config g++
    5. Execute the following command to check if the later version g++ is successfully selected:

      g++ --version
  4. Install Python Mech-Eye API.

    sudo pip3 install MechEyeApi

(Optional) Install Dependent Software Libraries

Some samples contain functions that depend on OpenCV. If you need to use the samples listed below, OpenCV must be installed (latest version recommended).

  • blind_spot_filtering

  • noise_removal

  • profile_alignment

  • render_depth_map

  • trigger_with_software_and_fixed_rate

  • trigger_with_external_device_and_fixed_rate

  • trigger_with_software_and_encoder

  • trigger_with_external_device_and_encoder

  • trigger_multiple_profilers_simultaneously

  • use_virtual_device

Execute the following command to install the latest version of OpenCV:

sudo apt-get install libopencv-dev
sudo apt-get install python3-opencv

Run Samples

The paths provided in this section correspond to the samples included in the installation path. If you are using the samples cloned from GitHub, please modify the paths correspondingly.

Follow these steps to run the samples:

  1. Navigate to the folder where a sample is located.

    cd ~/opt/mech-mind/mech-eye-sdk/samples/python/profiler
  2. Run the sample: replace sample_name with the name of the sample. While the sample is running, input the index of the laser profiler to which you want to connect according to the instruction, and press Enter to connect to the laser profiler.

    sudo python3 sample_name.py
  3. If image and/or point cloud files are saved by the sample, you can find the files in the folder where the sample is located.

When writing your own program, use the import command to import Mech-Eye API first:

python3
import MechEye
import open3d

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.