Python (Ubuntu)

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

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

Sample List

Samples are divided into the following categories: basic, advanced, and util.

  • basic samples: Connect and acquire data.

  • advanced samples: Acquire data in more complicated manners and set model-specific parameters.

  • util samples: Obtain camera information and set common parameters.

The samples in each category and their descriptions are provided below.

  • connect_to_camera: Connect to a camera.

  • connect_and_capture_images: Connect to a camera and obtain the 2D image, depth map, and point cloud data.

  • capture_2d_image: Obtain and save the 2D image.

  • capture_depth_map: Obtain and save the depth map.

  • capture_point_cloud: Obtain and save the untextured and textured point clouds.

  • capture_point_cloud_hdr: Set multiple exposure times, and then obtain and save the point cloud.

  • capture_point_cloud_with_normals: Calculate normals and save the point cloud with normals.

  • convert_depth_map_to_point_cloud: Generate a point cloud from the depth map and save the point cloud.

  • multiple_cameras_capture_sequentially: Obtain and save 2D images, depth maps, and point clouds sequentially from multiple cameras.

  • multiple_cameras_capture_simultaneously: Obtain and save 2D images, depth maps, and point clouds simultaneously from multiple cameras.

  • capture_periodically: Obtain and save 2D images, depth maps, and point clouds periodically for the specified duration from a camera.

  • mapping_2d_image_to_depth_map: Generate untextured and textured point clouds from a masked 2D image and a depth map.

  • set_parameters_of_laser_cameras: Set the parameters specific to laser cameras (the DEEP and LSR series).

  • set_parameters_of_uhp_cameras: Set the parameters specific to the UHP series.

  • register_camera_event: Define and register the callback function for monitoring the camera connection status.

  • get_camera_intrinsics: Obtain and print the camera intrinsic parameters.

  • print_camera_info: Obtain and print the camera information, such as model, serial number, firmware version, and temperatures.

  • set_scanning_parameters: Set the parameters in the 3D Parameters, 2D Parameters, and ROI categories.

  • set_depth_range: Set the Depth Range parameter.

  • set_point_cloud_processing_parameters: Set the Point Cloud Processing parameters.

  • 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.

  • save_and_load_user_set: Import and replace all parameter groups from a JSON file, and save all parameter groups to a JSON file.


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

  • Connect the camera and computer correctly.

  • Make sure that the version of Python installed 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

The Python samples can be obtained from GitHub by cloning:

cd ~
git clone

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

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. Upgrade g++ to ensure that its version is 12 or above.

    If the g++ version is lower than 12, import will fail.
    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
  3. 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 in the table below, you must install OpenCV (latest version recommended).

  • capture_2d_image

  • capture_depth_map

  • capture_periodically

  • multiple_cameras_capture_sequentially

  • multiple_cameras_capture_simultaneously

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

Follow these steps to run the samples:

  1. Navigate to the folder where a sample is located. Replace category with the category name of the sample.

    cd ~/mecheye_python_samples/area_scan_3d_camera/category
  2. Run the sample: replace sample_name with the name of the sample. While the sample is running, input the index of the camera to which you want to connect according to the instruction, and press Enter to connect to the camera.

    sudo python3
  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:

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.