C++ (Windows)
This topic introduces how to configure the Mech-Eye API C++ samples with CMake and then build the samples with Visual Studio on Windows.
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-GL (V4), LSR L-GL (V4), LSR S-GL (V4), and DEEP-GL (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.
Prerequisites
In order to use the C++ samples of Mech-Eye API, the following prerequisites must be satisfied:
-
Obtain the samples.
-
Install the required software.
-
(Optional) Install the software libraries on which samples depend and add relevant environment variables.
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 path are located in xxx/Mech-Eye SDK-2.4.1/API/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, Mech-Eye SDK, CMake and Visual Studio must be installed.
Install the Latest Version of Mech-Eye SDK
Please install or upgrade Mech-Eye SDK according to Mech-Eye SDK Installation Guide.
Install CMake (Version 3.2 or Above)
-
Download CMake: download the installer to the right of Windows x64 Installer.
-
When installing, select the following two options to add CMake to environment variables and create a desktop shortcut for CMake.
-
Add CMake to the system PATH for all users
-
Create Cmake Desktop Icon
-
Install Visual Studio (Version 2017 or Above)
-
Download the Visual Studio installer.
-
When installing, select the following two workloads in the Desktop & Mobile category, and then click Install.
-
Desktop development with C++
-
Universal Windows Platform development
-
Please restart your computer after installing Visual Studio. If you still need to install the optional software libraries, you can restart your computer after adding environment variables. |
(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: version 3.4.5 or above
-
PCL: version 1.8.1 or above
-
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
-
Download and install OpenCV. Note down the installation path of OpenCV.
-
Add OpenCV to environment variables. Refer to Add Environment Variables for instructions.
Install PCL
-
Refer to the following table and determine the version of PCL to install based on the version of Visual Studio.
Visual Studio version Supported PCL versions 2017
1.8.1–1.9.1
2019
1.8.1–1.12.1
2022
1.8.1 and above
-
Open the PCL download page, click Assets under the corresponding version, and download the EXE installer.
-
Run the installer to install PCL. When installing, select Add PCL to the system PATH for all users to add PCL to environment variables.
The following error message might pop up during installation:
Warning! PATH too long installer unable to modify PATH!
In this case, you need to add PCL to environment variables manually. Refer to Add Environment Variables for instructions.
-
Add OpenNI2 on which PCL depends to environment variables. Refer to Add Environment Variables for instructions.
Install HALCON
Install HALCON 20.11 or above. Please confirm that your HALCON license is still valid.
Add Environment Variables
If you need to use samples that depend on OpenCV or PCL, please add the relevant environment variables according to the following steps.
-
Right-click This PC on the desktop and select Properties.
-
Click Advanced system settings, and in the pop-up System Properties window, click Environment Variables to open the Environment Variables window.
-
Double-click Path in the user variables to enter the Edit environment variable page. Click New in the upper-right and add the following paths one by one. Then, click OK to exit the window.
-
For PCL: C:/Program Files/OpenNI2/Tools
-
For OpenCV:
-
xxx/OpenCV/build/x64/vc14/bin
-
xxx/OpenCV/build/x64/vc14/lib
-
-
If you encountered the error message while installing PCL, please add the following path as well:
-
xxx/PCL 1.12.1/bin
-
xxx/PCL 1.12.1/3rdParty/VTK/bin
-
-
It is recommended to restart your computer after adding the environmental variables. If not restarted, the environmental variables added may not be effective. |
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.
-
Open CMakeLists.txt in xxx/Mech-Eye SDK-2.4.1/API/samples/cpp/area_scan_3d_camera.
-
Edit lines containing
options
: find the lines starting withoptions
, changeON
at the end of the line toOFF
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 theoption(USE_HALCON…)
line toOFF
. -
Save the changes and close CMakeLists.txt.
Configure Samples in CMake
-
Right-click CMake and select Run as administrator.
-
Enter the paths of source code and binaries.
-
To build all samples at once, enter the following paths.
Where is the source code
xxx/Mech-Eye SDK-2.4.1/API/samples/cpp/area_scan_3d_camera
Where to build the binaries
xxx/Mech-Eye SDK-2.4.1/API/samples/cpp/area_scan_3d_camera/build
-
To build one sample individually, enter the following paths. Replace Category with the category name of the sample and SampleName with the name of the sample.
Where is the source code
xxx/Mech-Eye SDK-2.4.1/API/samples/cpp/area_scan_3d_camera/Category/SampleName
Where to build the binaries
xxx/Mech-Eye SDK-2.4.1/API/samples/cpp/area_scan_3d_camera/Category/SampleName/build
-
-
Click Configure in the bottom to open the configuration page. Select Visual Studio version, and set the platform to x64. Then, click Finish. When the configuration completes, the log will display Configuring done.
-
Click Generate to generate Visual Studio solution. When the generation completes, the log will display Generating done. Then, click Open Project to open the solution in Visual Studio.
Build Samples in Visual Studio
-
In Visual Studio toolbar, change the solution configuration from Debug to Release.
-
In the menu bar, select
. An executable file (.exe) is generated for each sample. The executable files are saved to the Release folder, located in the Where to build the binaries directory that you entered in CMake.
Run Samples
You can run the samples in Visual Studio after building them, or run the samples by double-clicking the executable files.
Run a Sample in Visual Studio
-
In the Solution Explorer panel, right-click a sample, and select Set as Startup Project.
-
Click Local Windows Debugger in the toolbar to run 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.
-
If image and/or point cloud files are saved by the sample, you can find the files in the build folder (the Where to build the binaries directory that you entered in CMake).
Run the Executable File of a Sample
-
Navigate to the Where to build the binaries directory that you entered in CMake, and open the Release folder.
-
Run the executable file with the same name as 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.
-
If image and/or point cloud files are saved by the sample, you can find the files in the Release folder.