C#

This topic introduces how to build the Mech-Eye API C# samples with Visual Studio on Windows.

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.

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.

  • 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 the camera connection status.

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

Prerequisites

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

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.3.3/API/samples/csharp/area_scan_3d_camera.

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

Install Required Software

In order to use the C++ samples of Mech-Eye API, Mech-Eye SDK, Visual Studio and Emgu CV 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 Visual Studio (Version 2019 or Above)

  1. Download the Visual Studio installer.

  2. When installing, select the following workloads and individual component, and then click Install.

    • Workloads in the Desktop & Mobile category:

      • .NET desktop development

      • Desktop development with C++

      • Universal Windows Platform development

    • Individual component: .NET Framework 4.8 targeting pack

C# Mech-Eye API is developed based on .NET Framework 4.8. If .NET Framework 4.8 is not installed, the samples cannot be built.

Install Emgu CV

The CaptureDepthMap sample contains functions that depend on the OpenCV software library. Therefore, Emgu CV (the .NET wrapper for OpenCV) must be installed through NuGet Package Manager in Visual Studio.

For detailed instructions, refer to the guide provided by Microsoft.

Build and Run Samples

After building the samples in Visual Studio, select the appropriate way to run the samples.

Build Samples in Visual Studio

  1. Double-click MechEyeCSharpSamples.sln in the area_scan_3d_camera folder.

  2. In Visual Studio toolbar, change the solution configuration from Debug to Release.

  3. In the menu bar, select Build  Build Solution. An executable file (.exe) is generated for each sample. The executable files are saved to the Build folder, located in the area_scan_3d_camera folder.

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

  1. In the Solution Explorer panel, right-click a sample, and select Set as Startup Project.

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

  3. If image and/or point cloud files are saved by the sample, you can find the files in the Build folder.

Run the Executable File of a Sample

  1. Enter the Build folder in the area_scan_3d_camera folder.

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

  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.