Mech-Eye API 2.5.1
API reference documentation for Mech-Eye Industrial 3D Camera
Loading...
Searching...
No Matches
SampleUtil.h
Go to the documentation of this file.
1/*******************************************************************************
2 *BSD 3-Clause License
3 *
4 *Copyright (c) 2016-2025, Mech-Mind Robotics Technologies Co., Ltd.
5 *All rights reserved.
6 *
7 *Redistribution and use in source and binary forms, with or without
8 *modification, are permitted provided that the following conditions are met:
9 *
10 *1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 *2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 *3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 *SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 *CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 *OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 *OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************************************************************/
32
33#pragma once
34#include <iostream>
35#include <set>
36#include <utility>
37#include "MechEyeApi.h"
38#include "MechEyeLNXApi.h"
39
40inline void showError(const mmind::api::ErrorStatus& status)
41{
42 if (status.isOK())
43 return;
44 std::cout << "Error Code : " << status.errorCode
45 << ", Error Description: " << status.errorDescription << std::endl;
46}
47
48inline void printDeviceInfo(const mmind::api::MechEyeDeviceInfo& deviceInfo)
49{
50 std::cout << "............................" << std::endl;
51 std::cout << "Camera Model Name: " << deviceInfo.model << std::endl;
52 std::cout << "Camera ID: " << deviceInfo.id << std::endl;
53 std::cout << "Camera IP Address: " << deviceInfo.ipAddress << std::endl;
54 std::cout << "Hardware Version: "
55 << "V" << deviceInfo.hardwareVersion << std::endl;
56 std::cout << "Firmware Version: "
57 << "V" << deviceInfo.firmwareVersion << std::endl;
58 std::cout << "............................" << std::endl;
59 std::cout << std::endl;
60}
61
62inline void printDeviceTemperature(const mmind::api::DeviceTemperature& deviceTemperature)
63{
64 std::cout << ".....Device Temperature....." << std::endl;
65 std::cout << "CPU : " << deviceTemperature.cpuTemperature << "°C" << std::endl;
66 std::cout << "Projector Module: " << deviceTemperature.projectorModuleTemperature << "°C"
67 << std::endl;
68 std::cout << "............................" << std::endl;
69
70 std::cout << std::endl;
71}
72
73inline bool isNumber(const std::string& str)
74{
75 for (char it : str) {
76 if (it < '0' || it > '9')
77 return false;
78 }
79 return true;
80}
81
82inline void printDeviceResolution(const mmind::api::DeviceResolution& deviceResolution)
83{
84 std::cout << "Color Map size : (width : " << deviceResolution.colorMapWidth
85 << ", height : " << deviceResolution.colorMapHeight << ")." << std::endl;
86 std::cout << "Depth Map size : (width : " << deviceResolution.depthMapWidth
87 << ", height : " << deviceResolution.depthMapHeight << ")." << std::endl;
88}
89
90inline void printCameraMatrix(const std::string& title, const double* cameraMatrix)
91{
92 std::cout << title << ": " << std::endl
93 << " [" << cameraMatrix[0] << ", " << 0 << ", " << cameraMatrix[2] << "]"
94
95 << std::endl
96 << " [" << 0 << ", " << cameraMatrix[1] << ", " << cameraMatrix[3] << "]"
97
98 << std::endl
99 << " [" << 0 << ", " << 0 << ", " << 1 << "]" << std::endl;
100 std::cout << std::endl;
101}
102
103inline void printCameraDistCoeffs(const std::string& title, const double* distCoeffs)
104{
105 std::cout << title << ": " << std::endl
106 << " k1: " << distCoeffs[0] << ", k2: " << distCoeffs[1]
107 << ", p1: " << distCoeffs[2] << ", p2: " << distCoeffs[3] << ", k3: " << distCoeffs[4]
108 << std::endl;
109 std::cout << std::endl;
110}
111
112inline void printTransform(const std::string& title, const mmind::api::Pose& pose)
113{
114 std::cout << "Rotation: " << title << ": " << std::endl;
115 for (int i = 0; i < 3; i++) {
116 std::cout << " [";
117 for (int j = 0; j < 3; j++) {
118 std::cout << pose.rotation[i][j];
119 if (j != 2)
120 std::cout << ", ";
121 }
122 std::cout << "]" << std::endl;
123 }
124 std::cout << std::endl;
125 std::cout << "Translation " << title << ": " << std::endl;
126 std::cout << " X: " << pose.translation[0] << "mm, Y: " << pose.translation[1]
127 << "mm, Z: " << pose.translation[2] << "mm" << std::endl;
128 std::cout << std::endl;
129}
130
131inline void printCalibParams(const mmind::api::DeviceIntri& deviceIntri)
132{
133 printCameraMatrix("Texture Camera Matrix", deviceIntri.textureCameraIntri.cameraMatrix);
134 printCameraDistCoeffs("Texture Camera Distortion Coefficients",
135 deviceIntri.textureCameraIntri.distortion);
136
137 printCameraMatrix("Depth Camera Matrix", deviceIntri.depthCameraIntri.cameraMatrix);
138 printCameraDistCoeffs("Depth Camera Distortion Coefficients",
139 deviceIntri.depthCameraIntri.distortion);
140
141 printTransform("from Depth Camera to Texture Camera", deviceIntri.depthToTexture);
142}
143
145{
146 std::cout << "Find Mech-Eye Industrial 3D Cameras..." << std::endl;
147 std::vector<mmind::api::MechEyeDeviceInfo> deviceInfoList =
149
150 if (deviceInfoList.empty()) {
151 std::cout << "No Mech-Eye Industrial 3D Cameras found." << std::endl;
152 return false;
153 }
154
155 for (int i = 0; i < deviceInfoList.size(); i++) {
156 std::cout << "Mech-Eye device index : " << i << std::endl;
157 printDeviceInfo(deviceInfoList[i]);
158 }
159
160 std::cout << "Please enter the device index you want to connect: ";
161 unsigned inputIndex = 0;
162
163 while (true) {
164 std::string str;
165 std::cin >> str;
166 if (isNumber(str) && atoi(str.c_str()) < deviceInfoList.size()) {
167 inputIndex = atoi(str.c_str());
168 break;
169 }
170 std::cout << "Input invalid! Please enter the device index you want to connect: ";
171 }
172
174 status = device.connect(deviceInfoList[inputIndex]);
175
176 if (!status.isOK()) {
177 showError(status);
178 return false;
179 }
180
181 std::cout << "Connect Mech-Eye Industrial 3D Camera Successfully." << std::endl;
182 return true;
183}
184
186{
187 std::cout << "Find Mech-Eye device..." << std::endl;
188 std::vector<mmind::api::MechEyeDeviceInfo> deviceInfoList =
190
191 std::vector<mmind::api::MechEyeDeviceInfo> lnxInfos;
192
193 for (const auto& info : deviceInfoList) {
194 if (info.model == "Mech-Eye LNX 8030")
195 lnxInfos.emplace_back(info);
196 }
197
198 if (lnxInfos.empty()) {
199 std::cout << "No Mech-Eye device found." << std::endl;
200 return false;
201 }
202
203 for (int i = 0; i < lnxInfos.size(); i++) {
204 std::cout << "Mech-Eye LNX device index : " << i << std::endl;
205 printDeviceInfo(lnxInfos[i]);
206 }
207
208 std::cout << "Please enter the device index you want to connect: ";
209 unsigned inputIndex = 0;
210
211 while (true) {
212 std::string str;
213 std::cin >> str;
214 if (isNumber(str) && atoi(str.c_str()) < lnxInfos.size()) {
215 inputIndex = atoi(str.c_str());
216 break;
217 }
218 std::cout << "Input invalid! Please enter the device index you want to connect: ";
219 }
220
222 status = device.connect(lnxInfos[inputIndex]);
223
224 if (!status.isOK()) {
225 showError(status);
226 return false;
227 }
228
229 std::cout << "Connect Mech-Eye Successfully." << std::endl;
230 return true;
231}
232
233inline std::pair<mmind::api::MechEyeDevice*, int> findAndConnectMulti()
234{
235 std::cout << "Find Mech-Eye Industrial 3D Cameras..." << std::endl;
236 std::vector<mmind::api::MechEyeDeviceInfo> deviceInfoList =
238
239 if (deviceInfoList.empty()) {
240 std::cout << "No Mech-Eye Industrial 3D Cameras found." << std::endl;
241 return std::make_pair(nullptr, 0);
242 }
243
244 for (int i = 0; i < deviceInfoList.size(); i++) {
245 std::cout << "Mech-Eye device index : " << i << std::endl;
246 printDeviceInfo(deviceInfoList[i]);
247 }
248
249 std::string str;
250 std::set<unsigned> indices;
251
252 while (true) {
253 std::cout << "Please enter the device index you want to connect: " << std::endl;
254 std::cout << "Enter a c to terminate adding devices" << std::endl;
255
256 std::cin >> str;
257 if (str == "c")
258 break;
259 if (isNumber(str) && atoi(str.c_str()) < deviceInfoList.size())
260 indices.emplace(atoi(str.c_str()));
261 else
262 std::cout << "Input invalid! Please enter the device index you want to connect: ";
263 }
264
265 auto* devices = new mmind::api::MechEyeDevice[indices.size()];
266
267 auto it = indices.begin();
268 for (int i = 0; i < indices.size() && it != indices.end(); ++i, ++it) {
269 showError(devices[i].connect(deviceInfoList[*it]));
270 }
271
272 return std::make_pair(devices, static_cast<int>(indices.size()));
273}
void printDeviceInfo(const mmind::api::MechEyeDeviceInfo &deviceInfo)
Definition SampleUtil.h:48
void printDeviceResolution(const mmind::api::DeviceResolution &deviceResolution)
Definition SampleUtil.h:82
void printDeviceTemperature(const mmind::api::DeviceTemperature &deviceTemperature)
Definition SampleUtil.h:62
std::pair< mmind::api::MechEyeDevice *, int > findAndConnectMulti()
Definition SampleUtil.h:233
void printCameraDistCoeffs(const std::string &title, const double *distCoeffs)
Definition SampleUtil.h:103
void printCameraMatrix(const std::string &title, const double *cameraMatrix)
Definition SampleUtil.h:90
bool findAndConnect(mmind::api::MechEyeDevice &device)
Definition SampleUtil.h:144
void printTransform(const std::string &title, const mmind::api::Pose &pose)
Definition SampleUtil.h:112
void showError(const mmind::api::ErrorStatus &status)
Definition SampleUtil.h:40
void printCalibParams(const mmind::api::DeviceIntri &deviceIntri)
Definition SampleUtil.h:131
bool isNumber(const std::string &str)
Definition SampleUtil.h:73
Interface that is used to connect the Mech-Eye Industrial 3D Camera and access basic information of t...
Definition MechEyeApi.h:58
static std::vector< MechEyeDeviceInfo > enumerateMechEyeDeviceList()
Enumerates Mech-Eye Industrial 3D Camera by the type of MechEyeDeviceInfo identifying the device.
ErrorStatus connect(const MechEyeDeviceInfo &info, int timeout=10000)
Connects to the device by the MechEyeDeviceInfo identifying a device.
Interface that is used to connect the LNX Mech-Eye device and access basic information of the device.
Definition MechEyeLNXApi.h:60
ErrorStatus connect(const MechEyeDeviceInfo &info, const int timeout=10000)
Connect to the device by the MechEyeDeviceInfo identifying a device.
static std::vector< api::MechEyeDeviceInfo > enumerateMechEyeDeviceList()
Enumerate Mech-Eye devices by the MechEyeDeviceInfo identifying the device.
double cameraMatrix[4]
Camera matrix, which arrange in [fx, fy, cx, cy].
Definition MechEyeDataType.h:113
double distortion[5]
Definition MechEyeDataType.h:111
This struct defines device intrinsic parameters, including texture camera and depth camera.
Definition MechEyeDataType.h:131
CameraIntri depthCameraIntri
The intrinsic parameters of the camera for capturing color map.
Definition MechEyeDataType.h:135
Pose depthToTexture
The intrinsic parameters of the camera for capturing depth map.
Definition MechEyeDataType.h:137
CameraIntri textureCameraIntri
Definition MechEyeDataType.h:133
This struct defines camera map resolution.
Definition MechEyeDataType.h:146
unsigned depthMapHeight
The height of the depth map.
Definition MechEyeDataType.h:150
unsigned colorMapWidth
The width of the color map.
Definition MechEyeDataType.h:147
unsigned colorMapHeight
The height of the color map.
Definition MechEyeDataType.h:148
unsigned depthMapWidth
The width of the depth map.
Definition MechEyeDataType.h:149
This struct describes the device temperature information.
Definition MechEyeDataType.h:101
float projectorModuleTemperature
projector module temperature in degrees Celsius.
Definition MechEyeDataType.h:103
float cpuTemperature
CPU temperature in the device motherboard in degrees Celsius.
Definition MechEyeDataType.h:102
This enumeration defines the types of errors.
Definition MechEyeDataType.h:45
std::string errorDescription
Definition MechEyeDataType.h:80
ErrorCode errorCode
Definition MechEyeDataType.h:75
bool isOK() const
Definition MechEyeDataType.h:70
This struct defines device information.
Definition MechEyeDataType.h:87
std::string model
Device model name, such as Mech-Eye Nano.
Definition MechEyeDataType.h:88
std::string hardwareVersion
The version of the hardware which is pre-determined from the factory.
Definition MechEyeDataType.h:91
std::string firmwareVersion
The version of the firmware which can be upgraded.
Definition MechEyeDataType.h:92
std::string ipAddress
IP address of the device.
Definition MechEyeDataType.h:93
std::string id
Device ID.
Definition MechEyeDataType.h:89
This struct defines rigid body transformations, including rotation matrix and translation vector.
Definition MechEyeDataType.h:121
double translation[3]
3*1 translation vector in [x(mm), y(mm), z(mm)].
Definition MechEyeDataType.h:123
double rotation[3][3]
3*3 rotation matrix.
Definition MechEyeDataType.h:122