Capture Tutorial

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

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.

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.

  • C++

  • C#

  • Python

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

  • C++

  • C#

  • Python

mmind::api::MechEyeDevice device;
device.connect(deviceInfoList[0]);
MechEyeDevice device = new MechEyeDevice();
device.Connect(deviceInfoList[0]);
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 the 2D image, you need to set the 2D Parameters, including Exposure Mode and Exposure Time.

  • C++

  • C#

  • Python

device.setScan2DExposureMode(mmind::api::Scanning2DSettings::Scan2DExposureMode::Timed);
device.setScan2DExposureTime(100);
device.SetScan2DExposureMode(Scan2DExposureMode.Timed);
device.SetScan2DExposureTime(100);
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, and Point Cloud Processing.

  • C++

  • C#

  • Python

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);
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);
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

  • C++

  • C#

  • Python

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

Obtain Point Cloud Data

  • C++

  • C#

  • Python

mmind::api::PointXYZMap pointXYZMap;
device.capturePointXYZMap(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.

  • C++

  • C#

  • Python

const std::string colorFile = "ColorMap.png";
cv::Mat color8UC3 = cv::Mat(colorMap.height(), colorMap.width(), CV_8UC3, colorMap.data());
cv::imwrite(colorFile, color8UC3);
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);
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.

  • C++

  • C#

  • Python

std::string pointCloudPath = "PointCloudXYZ.ply";
savePLY(pointXYZMap, pointCloudPath);
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);
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)

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.