Capture Tutorial

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

Attention

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 refer to the following topics and modify your program accordingly.

Requirements

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.

Detect Cameras (C++)

std::vector<mmind::api::MechEyeDeviceInfo> deviceInfoList = mmind::api::MechEyeDevice::enumerateMechEyeDeviceList();

Detect Cameras (C#)

List<MechEyeDeviceInfo> deviceInfoList = MechEyeDevice.EnumerateMechEyeDeviceList();

Detect Cameras (Python)

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 connecting to the first camera in the list).

Connect to a Camera (C++)

mmind::api::MechEyeDevice device;
device.connect(deviceInfoList[0]);

Connect to a Camera (C#)

MechEyeDevice device = new MechEyeDevice();
device.Connect(deviceInfoList[0]);

Connect to a Camera (Python)

self.device.connect(self.device_list[int(0)])

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 2D images, you need to set the 2D Parameters, including Exposure Mode, Exposure Time, etc.

Set Parameters for 2D Image (C++)

device.setScan2DExposureMode(mmind::api::Scanning2DSettings::Scan2DExposureMode::Timed);
device.setScan2DExposureTime(100);

Set Parameters for 2D Image (C#)

device.SetScan2DExposureMode(Scan2DExposureMode.Timed);
device.SetScan2DExposureTime(100);

Set Parameters for 2D Image (Python)

self.device.set_scan_2d_exposure_mode("Timed")
self.device.set_scan_2d_exposure_time(100.0)

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, Point Cloud Processing, etc.

Set Parameters for Depth Map and Point Cloud (C++)

device.setScan3DExposure(std::vector<double>{5, 10});
device.setDepthRange(mmind::api::DepthRange(100, 1000));
device.setScan3DROI(mmind::api::ROI(0, 0, 500, 500));
device.setCloudSmoothMode(
    mmind::api::PointCloudProcessingSettings::CloudSmoothMode::Normal);
device.setCloudOutlierFilterMode(
    mmind::api::PointCloudProcessingSettings::CloudOutlierFilterMode::Normal);

Set Parameters for Depth Map and Point Cloud (C#)

device.SetScan3DExposure(new List<double> {5, 10});
device.SetDepthRange(new DepthRange(100, 1000));
device.SetScan3DROI(new ROI(0, 0, 500, 500));
device.SetCloudSmoothMode(CloudSmoothMode.Normal);
device.SetCloudOutlierFilterMode(CloudOutlierFilterMode.Normal);

Set Parameters for Depth Map and Point Cloud (Python)

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)
self.device.set_cloud_smooth_mode("Normal")
self.device.set_cloud_outlier_filter_mode("Normal")

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

Obtain 2D Image Data (C++)

mmind::api::ColorMap color;
device.captureColorMap(color);

Obtain 2D Image Data (C#)

ColorMap color = new ColorMap();
device.CaptureColorMap(ref color);

Obtain 2D Image Data (Python)

color_map = device.capture_color()

Obtain Point Cloud Data

Obtain Point Cloud Data (C++)

mmind::api::PointXYZMap pointXYZMap;
device.capturePointXYZMap(pointXYZMap);

Obtain Point Cloud Data (C#)

PointXYZMap pointXYZMap = new PointXYZMap();
device.CapturePointXYZMap(ref pointXYZMap);

Obtain Point Cloud Data (Python)

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.

Save 2D Image (C++)

const std::string colorFile = "ColorMap.png";
cv::Mat color8UC3 = cv::Mat(colorMap.height(), colorMap.width(), CV_8UC3, colorMap.data());
cv::imwrite(colorFile, color8UC3);

Save 2D Image (C#)

string colorFile = "colorMap.png";
Mat color8UC3 = new Mat(unchecked((int)colorMap.height()), unchecked((int)colorMap.width()), DepthType.Cv8U, 3, colorMap.data(), unchecked((int)colorMap.width()) * 3);
CvInvoke.Imwrite(colorFile, color8UC3);

Save 2D Image (Python)

color_file = "ColorMap.png"
cv2.imwrite(color_file, color_map.data())

Save Point Cloud

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

Save Point Cloud (C++)

std::string pointCloudPath = "PointCloudXYZ.ply";
savePLY(pointXYZMap, pointCloudPath);

Save Point Cloud (C#)

Mat depth32FC3 = new Mat(unchecked((int)pointXYZMap.height()), unchecked((int)pointXYZMap.width()), DepthType.Cv32F, 3, pointXYZMap.data(), unchecked((int)pointXYZMap.width()) * 12);
string pointCloudPath = "pointCloudXYZ.ply";
CvInvoke.WriteCloud(pointCloudPath, depth32FC3);

Save Point Cloud (Python)

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)
o3d.io.write_point_cloud("PointCloudXYZ.ply", point_cloud_xyz)