C++ (Ubuntu)

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

Samples are divided into the following categories: Basic, Advanced, Util, Calibration, Pcl and Halcon.

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

  • Calibration samples: perform hand-eye calibration through Mech-Eye API.

  • Pcl samples: Use the PCL library to convert data structure and visualize data.

  • Halcon: obtain HALCON-readable point clouds through Mech-Eye API.

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

Basic
  • ConnectToCamera: Connect to a camera.

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

  • Capture2DImage: Obtain and save the 2D image.

  • CaptureDepthMap: Obtain and save the depth map.

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

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

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

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

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

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

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

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

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

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

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

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

  • RegisterCameraEvent: Define and register the callback function for monitoring camera events.

  • CaptureStereo2DImages: Obtain the 2D images from both 2D cameras of Deep (V3), Laser L Enhanced (V3), PRO XS (V4), LSR L (V4), LSR S (V4), and DEEP (V4).

Util
  • GetCameraIntrinsics: Obtain and print the camera intrinsic parameters.

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

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

  • SetDepthRange: Set the Depth Range parameter.

  • SetPointCloudProcessingParameters: Set the Point Cloud Processing parameters.

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

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

Calibration
  • HandEyeCalibration: Perform hand-eye calibration.

Pcl
  • ConvertPointCloudToPcl: Obtain the point cloud data from the camera and convert it to the PCL data structure.

  • ConvertPointCloudWithNormalsToPcl: Obtain the point cloud data with normals from the camera and convert it to the PCL data structure.

Halcon
  • ConvertPointCloudToObjectModel3D: Obtain the point cloud data from a camera, and then transform and save the point clouds using the HALCON C++ interface.

    This sample is not available on platforms based on the ARM64 architecture.

Prerequisites

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

  • Connect the camera and computer correctly.

  • The version of the Ubuntu operating system is 18 or above.

  • Obtain the samples.

  • Install the required software.

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

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/area_scan_3d_camera.

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

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 recommended

  • PCL: latest version recommended

  • HALCON: version 20.11 or above

    HALCON versions below 20.11 are not fully tested.

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 OpenCV PCL Halcon

Capture2DImage

CaptureDepthMap

MultipleCamerasCaptureSequentially

MultipleCamerasCaptureSimultaneously

CapturePeriodically

CaptureStereo2DImages

HandEyeCalibration

RenderDepthMap

ConvertPointCloudToObjectModel3D

ConvertPointCloudToPcl

ConvertPointCloudWithNormalsToPcl

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

Install PCL

Execute the following command to install PCL:

sudo apt-get install libpcl-dev
On different versions of Ubuntu, this command installs different versions of PCL. On Ubuntu 18.04, PCL 1.8.1 is installed; on Ubuntu 20.04, PCL 1.10.0 is installed.

Install HALCON

Follow these steps to install HALCON:

  1. After downloading the HALCON installer, execute the following command to install HALCON (taking version 20.11 as an example):

    tar zxvfHALCON-20.11.3.0-linux.tar.gz
    sudo sh install-linux.sh #Note down the installation directory ofHALCON.
  2. Add HALCON-relevant environment variables: open /etc/profile in an editor (such as vi) and paste the following lines to the end of the file. Replace /opt/halcon with the actual installation directory of HALCON.

    HALCONARCH=x64-linux; exportHALCONARCH
    HALCONROOT="/opt/halcon"; exportHALCONROOT
    HALCONEXAMPLES=${HALCONROOT}/examples; exportHALCONEXAMPLES
    HALCONIMAGES=${HALCONROOT}/examples/images; exportHALCONIMAGES
    PATH=${HALCONROOT}/bin/${HALCONARCH}:${PATH}; export PATH
    if [ ${LD_LIBRARY_PATH} ]; then
       LD_LIBRARY_PATH=${HALCONROOT}/lib/${HALCONARCH}:${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH
    else
       LD_LIBRARY_PATH=${HALCONROOT}/lib/${HALCONARCH}; export LD_LIBRARY_PATH
    fi
    • The changes are applied when you log in again. Or, you can run the source /etc/profile/ command before you configure and build the samples.

    • For more information, please refer to HALCON’s installation guide.

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, PCL or HALCON, please edit the CMakeLists file to disable these samples before building all samples at once.

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

  2. Edit lines containing options: find the lines starting with options, change ON at the end of the line to OFF to disable the samples that depend on the software library mentioned in that line.

    Example: If you do not need to build the sample that depends on HALCON, change ON at the end of the option(USE_HALCON…​) line to OFF.

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

Build the sample

Follow these steps to run the sample:

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

    • If you want to build all samples at once, use the following command.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/area_scan_3d_camera/
    • If you want to build a single sample individually, use the following command. Replace Category with the category name of the sample and SampleName with the name of the sample.

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/area_scan_3d_camera/Category/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, use the following command.

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

      cd /opt/mech-mind/mech-eye-sdk/samples/cpp/area_scan_3d_camera/Category/SampleName/build/
  2. Run the sample: replace SampleName 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 ./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.