-
Notifications
You must be signed in to change notification settings - Fork 143
/
api.h
407 lines (349 loc) · 9.83 KB
/
api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MYNTEYE_API_API_H_
#define MYNTEYE_API_API_H_
#pragma once
#include <functional>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <opencv2/core/core.hpp>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
struct DeviceInfo;
class Correspondence;
class Device;
class Synthetic;
namespace device {
class Frame;
} // namespace device
namespace api {
/**
* @ingroup datatypes
* API stream data.
*/
struct MYNTEYE_API StreamData {
/** ImgData. */
std::shared_ptr<ImgData> img;
/** Frame. */
cv::Mat frame;
/** Raw frame. */
std::shared_ptr<device::Frame> frame_raw;
/** Frame ID. */
std::uint16_t frame_id;
bool operator==(const StreamData &other) const {
if (img && other.img) {
return img->frame_id == other.img->frame_id &&
img->timestamp == other.img->timestamp;
}
return false;
}
};
/**
* @ingroup datatypes
* API motion data.
*/
struct MYNTEYE_API MotionData {
/** ImuData. */
std::shared_ptr<ImuData> imu;
bool operator==(const MotionData &other) const {
if (imu && other.imu) {
return imu->timestamp == other.imu->timestamp;
}
return false;
}
};
} // namespace api
/**
* The API class to communicate with MYNT® EYE device.
*/
class MYNTEYE_API API {
public:
/** The api::StreamData callback. */
using stream_callback_t = std::function<void(const api::StreamData &data)>;
/** The api::MotionData callback. */
using motion_callback_t = std::function<void(const api::MotionData &data)>;
/** The enable/disable switch callback. */
using stream_switch_callback_t = std::function<void(const Stream &stream)>;
explicit API(std::shared_ptr<Device> device, CalibrationModel calib_model);
virtual ~API();
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @return the API instance.
* @note This will init glog with args and call device::select() to select a
* device.
*/
static std::shared_ptr<API> Create(int argc, char *argv[]);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @param device the selected device.
* @return the API instance.
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create(
int argc, char *argv[], const std::shared_ptr<Device> &device);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(const std::shared_ptr<Device> &device);
/**
* Get the model.
*/
Model GetModel() const;
/**
* Supports the stream or not.
*/
bool Supports(const Stream &stream) const;
/**
* Supports the capability or not.
*/
bool Supports(const Capabilities &capability) const;
/**
* Supports the option or not.
*/
bool Supports(const Option &option) const;
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* Log all stream requests and prompt user to select one.
*/
StreamRequest SelectStreamRequest(bool *ok) const;
/**
* Get all stream requests of the capability.
*/
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
/**
* Config the stream request to the capability.
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the config stream requests of the capability.
*/
const StreamRequest &GetStreamRequest(const Capabilities &capability) const;
/**
* Get all stream requests of the key stream capability.
*/
const std::vector<StreamRequest> &GetStreamRequests() const;
/**
* Config the stream request to the key stream capability.
*/
void ConfigStreamRequest(const StreamRequest &request);
/**
* Get the config stream requests of the key stream capability.
*/
const StreamRequest &GetStreamRequest() const;
/**
* Get the device info.
*/
std::shared_ptr<DeviceInfo> GetInfo() const;
/**
* Get the device info.
*/
std::string GetInfo(const Info &info) const;
/**
* Get the sdk version.
*/
std::string GetSDKVersion() const;
/**
* @deprecated Get the intrinsics (pinhole) of stream.
*/
IntrinsicsPinhole GetIntrinsics(const Stream &stream) const;
/**
* Get the intrinsics of stream.
*/
template <typename T>
T GetIntrinsics(const Stream &stream) const;
/**
* Get the intrinsics base of stream.
*/
std::shared_ptr<IntrinsicsBase> GetIntrinsicsBase(const Stream &stream) const;
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
/**
* Log all option infos.
*/
void LogOptionInfos() const;
/**
* Get the option info.
*/
OptionInfo GetOptionInfo(const Option &option) const;
/**
* Get the option value.
*/
std::int32_t GetOptionValue(const Option &option) const;
/**
* Set the disparity computing method.
*/
void SetDisparityComputingMethodType(
const DisparityComputingMethod &MethodType);
/**
* Set the rectify bord cut alpha.
*/
void SetRectifyAlpha(const double &alpha);
/**
* Set if the duplicate frames is enable.
*/
void setDuplicate(bool isEnable);
/**
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Set the option value.
*/
bool SetOptionValue(const Option &option, std::uint64_t value);
/**
* Run the option action.
*/
bool RunOptionAction(const Option &option) const;
/**
* Set the callback of stream.
*/
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
/**
* Set the callback of motion.
*/
void SetMotionCallback(motion_callback_t callback);
/**
* Has the callback of stream.
*/
bool HasStreamCallback(const Stream &stream) const;
/**
* Has the callback of motion.
*/
bool HasMotionCallback() const;
/**
* Start capturing the source.
*/
void Start(const Source &source);
/**
* Stop capturing the source.
*/
void Stop(const Source &source);
/**
* Wait the streams are ready.
*/
void WaitForStreams();
/**
* Enable the data of stream.
* @note must enable the stream if it's a synthetic one. This means the stream
* in not native, the device has the capability to provide this stream, but
* still support this stream.
*/
void EnableStreamData(const Stream &stream);
/**
* Enable the data of stream.
* callback function will call before the father processor enable.
* when try_tag is true, the function will do nothing except callback.
*/
void EnableStreamData(
const Stream &stream,
stream_switch_callback_t callback,
bool try_tag = false);
/**
* Disable the data of stream.
*/
void DisableStreamData(const Stream &stream);
/**
* Disable the data of stream.
* callback function will call before the children processor disable.
* when try_tag is true, the function will do nothing except callback.
*/
void DisableStreamData(
const Stream &stream,
stream_switch_callback_t callback,
bool try_tag = false);
/**
* Get the latest data of stream.
*/
api::StreamData GetStreamData(const Stream &stream);
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(
std::size_t max_size = std::numeric_limits<std::size_t>::max());
/**
* Get the motion datas.
*/
std::vector<api::MotionData> GetMotionDatas();
/**
* enable motion datas timestamp correspondence in device.
*/
void EnableImuTimestampCorrespondence(bool is_enable);
/**
* Enable motion datas with timestamp correspondence of some stream in api.
*/
void EnableTimestampCorrespondence(const Stream &stream,
bool keep_accel_then_gyro = true);
/**
* Enable the plugin.
*/
void EnablePlugin(const std::string &path);
std::shared_ptr<Device> device();
/** Enable process mode, e.g. imu assembly, temp_drift */
void EnableProcessMode(const ProcessMode& mode);
/** Enable process mode, e.g. imu assembly, temp_drift */
void EnableProcessMode(const std::int32_t& mode);
/**
* Get ROS need camera info struct
*/
std::shared_ptr<struct CameraROSMsgInfoPair> GetCameraROSMsgInfoPair();
/**
* Load disparity config from file.
*/
bool ConfigDisparityFromFile(const std::string& config_file);
bool IsDefaultIntrinsics();
private:
std::shared_ptr<Device> device_;
std::unique_ptr<Synthetic> synthetic_;
std::unique_ptr<Correspondence> correspondence_;
motion_callback_t callback_;
bool api_correspondence_enable_;
bool dev_correspondence_enable_;
void CheckImageParams();
};
template <typename T>
T API::GetIntrinsics(const Stream &stream) const {
auto in = GetIntrinsicsBase(stream);
return *std::dynamic_pointer_cast<T>(in);
}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_API_H_