Rearrage include and src
This commit is contained in:
285
include/mynteye/api/api.h
Normal file
285
include/mynteye/api/api.h
Normal file
@@ -0,0 +1,285 @@
|
||||
// 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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
#include "mynteye/types.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
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->frame_id == other.imu->frame_id &&
|
||||
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)>;
|
||||
|
||||
explicit API(std::shared_ptr<Device> device);
|
||||
virtual ~API();
|
||||
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @return the API instance.
|
||||
* @note This will call device::select() to select a device.
|
||||
*/
|
||||
static std::shared_ptr<API> Create();
|
||||
/**
|
||||
* Create the API instance.
|
||||
* @param device the selected device.
|
||||
* @return the API instance.
|
||||
*/
|
||||
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
|
||||
/**
|
||||
* 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[], 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;
|
||||
|
||||
/**
|
||||
* 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 device info.
|
||||
*/
|
||||
std::string GetInfo(const Info &info) const;
|
||||
|
||||
/**
|
||||
* Get the intrinsics of stream.
|
||||
*/
|
||||
Intrinsics GetIntrinsics(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 option value.
|
||||
*/
|
||||
void SetOptionValue(const Option &option, std::int32_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);
|
||||
/**
|
||||
* Disable the data of stream.
|
||||
*/
|
||||
void DisableStreamData(const Stream &stream);
|
||||
|
||||
/**
|
||||
* 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 the plugin.
|
||||
*/
|
||||
void EnablePlugin(const std::string &path);
|
||||
|
||||
std::shared_ptr<Device> device();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Device> device_;
|
||||
|
||||
std::unique_ptr<Synthetic> synthetic_;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_API_API_H_
|
||||
115
include/mynteye/api/object.h
Normal file
115
include/mynteye/api/object.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// 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_OBJECT_H_
|
||||
#define MYNTEYE_API_OBJECT_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
/**
|
||||
* Input & output object.
|
||||
*/
|
||||
struct MYNTEYE_API Object {
|
||||
Object() = default;
|
||||
virtual ~Object() = default;
|
||||
|
||||
virtual Object *Clone() const = 0;
|
||||
virtual bool DecValidity() const = 0;
|
||||
|
||||
/** Cast the obj to T pointer */
|
||||
template <typename T>
|
||||
static T *Cast(Object *obj) {
|
||||
return dynamic_cast<T *>(obj);
|
||||
}
|
||||
|
||||
/** Cast the obj to const T pointer */
|
||||
template <typename T>
|
||||
static const T *Cast(const Object *obj) {
|
||||
return dynamic_cast<const T *>(obj);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::shared_ptr<T> Cast(const std::shared_ptr<Object> &obj) {
|
||||
return std::dynamic_pointer_cast<T>(obj);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Input & output object of one cv::Mat.
|
||||
*/
|
||||
struct MYNTEYE_API ObjMat : public Object {
|
||||
ObjMat() = default;
|
||||
ObjMat(const cv::Mat &value, std::uint16_t id)
|
||||
: value(value), id(id) {}
|
||||
|
||||
/** The value */
|
||||
cv::Mat value;
|
||||
/** The id **/
|
||||
std::uint16_t id;
|
||||
|
||||
Object *Clone() const {
|
||||
ObjMat *mat = new ObjMat;
|
||||
mat->value = value.clone();
|
||||
mat->id = id;
|
||||
return mat;
|
||||
}
|
||||
|
||||
bool DecValidity() const {
|
||||
return !value.empty();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Input & output object of two cv::Mat.
|
||||
*/
|
||||
struct MYNTEYE_API ObjMat2 : public Object {
|
||||
ObjMat2() = default;
|
||||
ObjMat2(const cv::Mat &first, std::uint16_t first_id,
|
||||
const cv::Mat &second, std::uint16_t second_id)
|
||||
: first(first), first_id(first_id),
|
||||
second(second), second_id(second_id) {}
|
||||
|
||||
/** The first value */
|
||||
cv::Mat first;
|
||||
/** The first id **/
|
||||
std::uint16_t first_id;
|
||||
|
||||
/** The second value */
|
||||
cv::Mat second;
|
||||
/** The second id **/
|
||||
std::uint16_t second_id;
|
||||
|
||||
Object *Clone() const {
|
||||
ObjMat2 *mat2 = new ObjMat2;
|
||||
mat2->first = first.clone();
|
||||
mat2->first_id = first_id;
|
||||
mat2->second = second.clone();
|
||||
mat2->second_id = second_id;
|
||||
return mat2;
|
||||
}
|
||||
|
||||
bool DecValidity() const {
|
||||
return !first.empty() && !second.empty();
|
||||
}
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_API_OBJECT_H_
|
||||
141
include/mynteye/api/plugin.h
Normal file
141
include/mynteye/api/plugin.h
Normal file
@@ -0,0 +1,141 @@
|
||||
// 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_PLUGIN_H_
|
||||
#define MYNTEYE_API_PLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
#ifndef MYNTEYE_PLUGIN_VERSION_CODE
|
||||
#define MYNTEYE_PLUGIN_VERSION_CODE 0
|
||||
#endif
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
class API;
|
||||
struct Object;
|
||||
|
||||
/**
|
||||
* The plugin which could implement processing by yourself.
|
||||
*/
|
||||
class MYNTEYE_API Plugin {
|
||||
public:
|
||||
Plugin() = default;
|
||||
virtual ~Plugin() = 0;
|
||||
|
||||
/**
|
||||
* Called when plugin created.
|
||||
* @param api the API instacne.
|
||||
*/
|
||||
virtual void OnCreate(API *api) {
|
||||
api_ = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process rectify.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process rectify.
|
||||
*/
|
||||
virtual bool OnRectifyProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process disparity.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process disparity.
|
||||
*/
|
||||
virtual bool OnDisparityProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process normalized disparity.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process normalized disparity.
|
||||
*/
|
||||
virtual bool OnDisparityNormalizedProcess(
|
||||
Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process points.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process points.
|
||||
*/
|
||||
virtual bool OnPointsProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when process depth.
|
||||
* @param in input object.
|
||||
* @param out output object.
|
||||
* @return `true` if you process depth.
|
||||
*/
|
||||
virtual bool OnDepthProcess(Object *const in, Object *const out) {
|
||||
MYNTEYE_UNUSED(in)
|
||||
MYNTEYE_UNUSED(out)
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
API *api_;
|
||||
};
|
||||
|
||||
inline Plugin::~Plugin() = default;
|
||||
|
||||
using plugin_version_code_t = std::uint32_t();
|
||||
using plugin_create_t = Plugin *();
|
||||
using plugin_destroy_t = void(Plugin *);
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* Get the plugin version code.
|
||||
*/
|
||||
MYNTEYE_API std::uint32_t plugin_version_code();
|
||||
|
||||
/**
|
||||
* Create the plugin.
|
||||
*/
|
||||
MYNTEYE_API mynteye::Plugin *plugin_create();
|
||||
|
||||
/**
|
||||
* Destroy the plugin.
|
||||
*/
|
||||
MYNTEYE_API void plugin_destroy(mynteye::Plugin *plugin);
|
||||
|
||||
}
|
||||
|
||||
#endif // MYNTEYE_API_PLUGIN_H_
|
||||
Reference in New Issue
Block a user