Capture Tutorial

This topic describes how to use Mech-Eye API to connect to a camera, set camera parameters, obtain and save the data.

Mech-Eye API 2.0.0 updated the method and parameter names of C++ and C#. If you have installed Mech-Eye SDK 2.0.0 but still use programs written before, please modify the parameter names in your programs according to the following table.


For C++, C# and Python, please install Mech-Eye SDK first.

Also for Python, please complete the relevant configurations.

Detect Cameras

Once the requirements are satisfied, you can detect the connectable cameras using the following commands.

std::vector<mmind::api::MechEyeDeviceInfo> deviceInfoList = mmind::api::MechEyeDevice::enumerateMechEyeDeviceList();
List<MechEyeDeviceInfo> deviceInfoList = MechEyeDevice.EnumerateMechEyeDeviceList();
self.device_list = self.device.get_device_list()

Connect to a Camera

After finding the connectable cameras, you can connect to a camera using the following commands (Example codes connect to the first camera in the list).

mmind::api::MechEyeDevice device;
MechEyeDevice device = new MechEyeDevice();

Set the Camera Parameters

After connecting to the camera, you can set the camera parameters using the following commands.

Set Parameters for 2D Image

Before capturing the 2D image, you need to set the 2D Parameters, including Exposure Mode and Exposure Time.


Set Parameters for Depth Map and Point Cloud

Before capturing images used for calculating depth data, you need to set the parameters that affect the quality of the depth map and point cloud, including Exposure Time, Depth Range, ROI, and Point Cloud Processing.

device.setScan3DExposure(std::vector<double>{5, 10});
device.setDepthRange(mmind::api::DepthRange(100, 1000));
device.setScan3DROI(mmind::api::ROI(0, 0, 500, 500));
device.SetScan3DExposure(new List<double> {5, 10});
device.SetDepthRange(new DepthRange(100, 1000));
device.SetScan3DROI(new ROI(0, 0, 500, 500));
self.device.set_scan_3d_exposure([5.0, 10.0])
self.device.set_depth_range(100, 1000)
self.device.set_scan_3d_roi(0, 0, 500, 500)

Obtain Data

After setting the parameters, you can trigger the camera to capture images and return the 2D image and point cloud data.

Obtain 2D Image Data

mmind::api::ColorMap color;
ColorMap color = new ColorMap();
device.CaptureColorMap(ref color);
color_map = device.capture_color()

Obtain Point Cloud Data

mmind::api::PointXYZMap pointXYZMap;
PointXYZMap pointXYZMap = new PointXYZMap();
device.CapturePointXYZMap(ref pointXYZMap);
point_xyz = device.capture_point_xyz()

Save Data

Save 2D Image

You can convert the obtained 2D image data to OpenCV format and save the 2D image as a PNG file.

const std::string colorFile = "ColorMap.png";
cv::Mat color8UC3 = cv::Mat(colorMap.height(), colorMap.width(), CV_8UC3,;
cv::imwrite(colorFile, color8UC3);
string colorFile = "colorMap.png";
Mat color8UC3 = new Mat(unchecked((int)colorMap.height()), unchecked((int)colorMap.width()), DepthType.Cv8U, 3,, unchecked((int)colorMap.width()) * 3);
CvInvoke.Imwrite(colorFile, color8UC3);
color_file = "ColorMap.png"

Save Point Cloud

You can save the point cloud data as a PLY file.

std::string pointCloudPath = "PointCloudXYZ.ply";
savePLY(pointXYZMap, pointCloudPath);
Mat depth32FC3 = new Mat(unchecked((int)pointXYZMap.height()), unchecked((int)pointXYZMap.width()), DepthType.Cv32F, 3,, unchecked((int)pointXYZMap.width()) * 12);
string pointCloudPath = "pointCloudXYZ.ply";
CvInvoke.WriteCloud(pointCloudPath, depth32FC3);
point_cloud_xyz = o3d.geometry.PointCloud()
points_xyz = np.zeros(
    (point_xyz.width() * point_xyz.height(), 3), dtype=np.float64)

pos = 0
for dd in np.nditer(point_xyz_data):
    points_xyz[int(pos / 3)][int(pos % 3)]= 0.001 * dd
    pos = pos + 1

point_cloud_xyz.points = o3d.utility.Vector3dVector(points_xyz)"PointCloudXYZ.ply", point_cloud_xyz)