MYNT-EYE-S-SDK/include/mynteye/api/api.h

286 lines
6.6 KiB
C
Raw Normal View History

2018-05-10 09:46:34 +03:00
// 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.
2018-10-27 16:24:04 +03:00
#ifndef MYNTEYE_API_API_H_
#define MYNTEYE_API_API_H_
2018-04-25 11:06:38 +03:00
#pragma once
2018-04-26 09:44:47 +03:00
#include <limits>
2018-04-26 04:22:29 +03:00
#include <memory>
2018-04-26 05:33:37 +03:00
#include <string>
#include <vector>
2018-04-26 04:22:29 +03:00
2018-10-27 16:24:04 +03:00
#include <opencv2/core/core.hpp>
2018-04-25 11:06:38 +03:00
#include "mynteye/mynteye.h"
2018-04-26 05:33:37 +03:00
#include "mynteye/types.h"
2018-04-25 11:06:38 +03:00
MYNTEYE_BEGIN_NAMESPACE
2018-04-26 04:22:29 +03:00
class Device;
2018-04-26 05:33:37 +03:00
class Synthetic;
2018-04-26 04:22:29 +03:00
2018-06-07 12:39:51 +03:00
namespace device {
class Frame;
} // namespace device
2018-04-26 09:44:47 +03:00
namespace api {
2018-05-16 05:31:31 +03:00
/**
* @ingroup datatypes
* API stream data.
*/
2018-04-26 09:44:47 +03:00
struct MYNTEYE_API StreamData {
2018-05-16 05:31:31 +03:00
/** ImgData. */
2018-04-26 09:44:47 +03:00
std::shared_ptr<ImgData> img;
2018-05-16 05:31:31 +03:00
/** Frame. */
2018-04-26 09:44:47 +03:00
cv::Mat frame;
2018-06-07 12:39:51 +03:00
/** Raw frame. */
std::shared_ptr<device::Frame> frame_raw;
2018-10-26 10:39:34 +03:00
/** Frame ID. */
std::uint16_t frame_id;
2018-05-20 04:25:30 +03:00
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;
}
2018-04-26 09:44:47 +03:00
};
2018-05-16 05:31:31 +03:00
/**
* @ingroup datatypes
* API motion data.
*/
2018-04-26 09:44:47 +03:00
struct MYNTEYE_API MotionData {
2018-05-16 05:31:31 +03:00
/** ImuData. */
2018-04-26 09:44:47 +03:00
std::shared_ptr<ImuData> imu;
2018-05-20 04:25:30 +03:00
bool operator==(const MotionData &other) const {
if (imu && other.imu) {
return imu->frame_id == other.imu->frame_id &&
imu->timestamp == other.imu->timestamp;
}
return false;
}
2018-04-26 09:44:47 +03:00
};
} // namespace api
2018-05-16 05:31:31 +03:00
/**
* The API class to communicate with MYNT® EYE device.
*/
2018-04-25 11:06:38 +03:00
class MYNTEYE_API API {
public:
2018-05-16 05:31:31 +03:00
/** The api::StreamData callback. */
2018-04-26 09:44:47 +03:00
using stream_callback_t = std::function<void(const api::StreamData &data)>;
2018-05-16 05:31:31 +03:00
/** The api::MotionData callback. */
2018-04-26 09:44:47 +03:00
using motion_callback_t = std::function<void(const api::MotionData &data)>;
2018-04-26 04:22:29 +03:00
explicit API(std::shared_ptr<Device> device);
2018-05-20 04:25:30 +03:00
virtual ~API();
2018-04-26 04:22:29 +03:00
2018-05-15 17:01:15 +03:00
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
2018-04-26 04:22:29 +03:00
static std::shared_ptr<API> Create();
2018-05-15 17:01:15 +03:00
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
2018-04-26 04:22:29 +03:00
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
2018-05-15 17:01:15 +03:00
/**
* 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.
*/
2018-05-03 11:33:27 +03:00
static std::shared_ptr<API> Create(int argc, char *argv[]);
2018-05-15 17:01:15 +03:00
/**
* 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.
*/
2018-05-03 11:33:27 +03:00
static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device);
2018-04-26 04:22:29 +03:00
2018-05-16 05:31:31 +03:00
/**
* Get the model.
*/
2018-04-26 05:33:37 +03:00
Model GetModel() const;
2018-05-16 05:31:31 +03:00
/**
* Supports the stream or not.
*/
2018-04-26 05:33:37 +03:00
bool Supports(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the capability or not.
*/
2018-04-26 05:33:37 +03:00
bool Supports(const Capabilities &capability) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the option or not.
*/
2018-04-26 05:33:37 +03:00
bool Supports(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
2018-04-26 05:33:37 +03:00
2018-05-16 05:31:31 +03:00
/**
* Get all stream requests of the capability.
*/
2018-04-26 05:33:37 +03:00
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
2018-05-16 05:31:31 +03:00
/**
* Config the stream request to the capability.
*/
2018-04-26 05:33:37 +03:00
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
2018-05-16 05:31:31 +03:00
/**
* Get the device info.
*/
2018-04-26 05:33:37 +03:00
std::string GetInfo(const Info &info) const;
2018-05-16 05:31:31 +03:00
/**
* Get the intrinsics of stream.
*/
2018-04-26 05:33:37 +03:00
Intrinsics GetIntrinsics(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Get the extrinsics from one stream to another.
*/
2018-04-26 05:33:37 +03:00
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
2018-05-16 05:31:31 +03:00
/**
* Get the intrinsics of motion.
*/
2018-04-26 05:33:37 +03:00
MotionIntrinsics GetMotionIntrinsics() const;
2018-05-16 05:31:31 +03:00
/**
* Get the extrinsics from one stream to motion.
*/
2018-04-26 05:33:37 +03:00
Extrinsics GetMotionExtrinsics(const Stream &from) const;
2018-05-16 05:31:31 +03:00
/**
* Log all option infos.
*/
2018-04-26 05:33:37 +03:00
void LogOptionInfos() const;
2018-05-16 05:31:31 +03:00
/**
* Get the option info.
*/
2018-04-26 05:33:37 +03:00
OptionInfo GetOptionInfo(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Get the option value.
*/
2018-04-26 05:33:37 +03:00
std::int32_t GetOptionValue(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Set the option value.
*/
2018-04-26 05:33:37 +03:00
void SetOptionValue(const Option &option, std::int32_t value);
2018-05-16 05:31:31 +03:00
/**
* Run the option action.
*/
2018-04-26 05:33:37 +03:00
bool RunOptionAction(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Set the callback of stream.
*/
2018-04-26 09:44:47 +03:00
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
2018-05-16 05:31:31 +03:00
/**
* Set the callback of motion.
*/
2018-04-26 09:44:47 +03:00
void SetMotionCallback(motion_callback_t callback);
2018-05-16 05:31:31 +03:00
/**
* Has the callback of stream.
*/
2018-04-26 09:44:47 +03:00
bool HasStreamCallback(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Has the callback of motion.
*/
2018-04-26 09:44:47 +03:00
bool HasMotionCallback() const;
2018-05-16 05:31:31 +03:00
/**
* Start capturing the source.
*/
2018-04-26 09:44:47 +03:00
void Start(const Source &source);
2018-05-16 05:31:31 +03:00
/**
* Stop capturing the source.
*/
2018-04-26 09:44:47 +03:00
void Stop(const Source &source);
2018-05-16 05:31:31 +03:00
/**
* Wait the streams are ready.
*/
2018-04-26 09:44:47 +03:00
void WaitForStreams();
2018-05-16 05:31:31 +03:00
/**
* 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.
*/
2018-04-27 04:58:53 +03:00
void EnableStreamData(const Stream &stream);
2018-05-16 05:31:31 +03:00
/**
* Disable the data of stream.
*/
void DisableStreamData(const Stream &stream);
2018-05-16 05:31:31 +03:00
/**
2018-06-12 05:46:39 +03:00
* Get the latest data of stream.
2018-05-16 05:31:31 +03:00
*/
2018-04-26 09:44:47 +03:00
api::StreamData GetStreamData(const Stream &stream);
2018-05-16 05:31:31 +03:00
/**
2018-06-12 05:46:39 +03:00
* Get the datas of stream.
* @note default cache 4 datas at most.
2018-05-16 05:31:31 +03:00
*/
2018-04-26 09:44:47 +03:00
std::vector<api::StreamData> GetStreamDatas(const Stream &stream);
2018-05-16 05:31:31 +03:00
/**
* Enable cache motion datas.
*/
2018-04-26 09:44:47 +03:00
void EnableMotionDatas(
std::size_t max_size = std::numeric_limits<std::size_t>::max());
2018-05-16 05:31:31 +03:00
/**
* Get the motion datas.
*/
2018-04-26 09:44:47 +03:00
std::vector<api::MotionData> GetMotionDatas();
2018-05-16 05:31:31 +03:00
/**
* Enable the plugin.
*/
2018-05-08 06:12:45 +03:00
void EnablePlugin(const std::string &path);
2018-04-26 05:33:37 +03:00
std::shared_ptr<Device> device();
2018-04-26 04:22:29 +03:00
private:
std::shared_ptr<Device> device_;
2018-04-26 05:33:37 +03:00
std::unique_ptr<Synthetic> synthetic_;
2018-04-25 11:06:38 +03:00
};
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_API_API_H_