C++ (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 configure the Mech-Eye API C++ samples with CMake and then build the samples with the make command on Ubuntu.

Sample List

The following samples are currently provided:

  • AcquireProfileData: Acquire the profile data, generate the intensity image and depth map, and save the images.

  • AcquireProfileDataUsingCallback: Acquire the profile data using a callback function, generate the intensity image and depth map, and save the images.

  • AcquirePointCloud: Acquire the profile data, generate the point cloud, and save the point cloud in the CSV and PLY formats.

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

  • RegisterProfilerEvent: Define and register the callback function for monitoring the laser profiler connection status.

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

Prerequisites

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

If using a Ubuntu virtual machine, please ensure that the available disk space is greater than 20 GB. Otherwise, installation of the software may fail.

Obtain Samples

C++ 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/cpp/profiler.

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

Install Required Software

In order to use the C++ samples of Mech-Eye API, the software source list must be updated, and Mech-Eye SDK and dependencies must be installed.

  1. Update software source list:

    sudo apt-get update
  2. Install dependencies:

    sudo apt-get install -y build-essential pkg-config cmake
  3. Install Mech-Eye SDK: Please refer to Mech-Eye SDK Installation Guide (Ubuntu).

(Optional) Install Dependent Software Libraries

Some samples contain functions that depend on the following third-party software libraries. If you need to use the samples listed in the table below, you must install the software libraries on which the samples depend.

  • OpenCV: latest version

If any of the optional software libraries is not installed, then you must complete the steps in Disable Unneeded Samples (Optional) before configuring the samples.

Refer to the following table for the samples that depend on third-party software libraries.

Sample

AcquireProfileData

AcquireProfileDataUsingCallback

UseVirtualDevice

Install OpenCV

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

sudo apt update && sudo apt install -y unzip
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
mkdir build && cd build
cmake ../opencv-4.x
cmake --build .
sudo make install

Build and Run Samples

You can build all samples at once or build a single sample individually.

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.

Disable Unneeded Samples (Optional)

If you did not install some of the optional software libraries and still want to build all samples at once, then you must complete the steps in this section. Otherwise, an error will occur during the configuration of samples using CMake.

If you do not need the samples that depend on OpenCV, please edit the CMakeLists file to disable these samples before building all samples at a time.

  1. Open /opt/mech-mind/eye-sdk/samples/cpp/profiler/CMakeLists.txt in an editor (such as vi).

  2. Edit the line containing options: find the line of option(USE_OPENCV…​), change ON at the end of the line to OFF to disable the samples that depend on OpenCV.

  3. Save the changes in the editor and close the CMakeLists file.

Build the sample

Please follow these steps to run the sample:

  1. Enter the directory of the sample(s):

    • If building all samples at once, please use the following command.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/profiler/
    • If building a single sample individually, please use the following command. Replace SampleName with the name of the sample.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/profiler/SampleName/
  2. Create a build folder in the directory for saving the built samples and so on.

    sudo mkdir build && cd build
  3. Configure and build the sample(s):

    sudo cmake ..
    sudo make
If the source code files in the sample folder are altered, please delete the build folder and repeat steps 2 and 3 to rebuild the samples.

Run Samples

After building the samples, follow these steps to run the sample:

  1. Enter the build folder in the directory of the sample(s) (Skip this step if you are running the sample(s) directly after building the sample(s):

    • If all samples were built at once, please use the following command.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/profiler/build/
    • If a single sample was built individually, please use the following command. Replace SampleName with the name of the sample.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/profiler/SampleName/build/
  2. Run the sample: replace SampleName 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 ./SampleName
  3. If image and/or point cloud files are saved by the sample, you can find the files in the build folder.

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.