Check image params when use api
This commit is contained in:
parent
377f9b21f1
commit
92b38291ee
|
@ -29,6 +29,7 @@
|
|||
#include "api/plugin.h"
|
||||
#include "api/synthetic.h"
|
||||
#include "device/device.h"
|
||||
#include "device/device_s.h"
|
||||
#include "internal/dl.h"
|
||||
|
||||
#if defined(WITH_FILESYSTEM) && defined(WITH_NATIVE_FILESYSTEM)
|
||||
|
@ -73,12 +74,14 @@ bool dir_exists(const fs::path &p) {
|
|||
|
||||
bool file_exists(const std::string &p) {
|
||||
DWORD attrs = GetFileAttributes(p.c_str());
|
||||
return (attrs != INVALID_FILE_ATTRIBUTES && !(attrs & FILE_ATTRIBUTE_DIRECTORY));
|
||||
return (attrs != INVALID_FILE_ATTRIBUTES) &&
|
||||
!(attrs & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
bool dir_exists(const std::string &p) {
|
||||
DWORD attrs = GetFileAttributes(p.c_str());
|
||||
return (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY));
|
||||
return (attrs != INVALID_FILE_ATTRIBUTES) &&
|
||||
(attrs & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -207,9 +210,24 @@ std::vector<std::string> get_plugin_paths() {
|
|||
|
||||
} // namespace
|
||||
|
||||
API::API(std::shared_ptr<Device> device)
|
||||
: device_(device), synthetic_(new Synthetic(this)) {
|
||||
API::API(std::shared_ptr<Device> device) : device_(device) {
|
||||
VLOG(2) << __func__;
|
||||
if (std::dynamic_pointer_cast<StandardDevice>(device_) != nullptr) {
|
||||
bool in_l_ok, in_r_ok, ex_l2r_ok;
|
||||
device_->GetIntrinsics(Stream::LEFT, &in_l_ok);
|
||||
device_->GetIntrinsics(Stream::RIGHT, &in_r_ok);
|
||||
device_->GetExtrinsics(Stream::LEFT, Stream::RIGHT, &ex_l2r_ok);
|
||||
if (!in_l_ok || !in_r_ok || !ex_l2r_ok) {
|
||||
LOG(FATAL) << "Image params not found, but we need it to process the "
|
||||
"images. Please `make tools` and use `img_params_writer` "
|
||||
"to write the image params. If you update the SDK from "
|
||||
"1.x, the `SN*.conf` is the file contains them. Besides, "
|
||||
"you could also calibrate them by yourself. Read the guide "
|
||||
"doc (https://github.com/slightech/MYNT-EYE-SDK-2-Guide) "
|
||||
"to learn more.";
|
||||
}
|
||||
}
|
||||
synthetic_.reset(new Synthetic(this));
|
||||
}
|
||||
|
||||
API::~API() {
|
||||
|
|
|
@ -198,21 +198,47 @@ std::string Device::GetInfo(const Info &info) const {
|
|||
}
|
||||
|
||||
Intrinsics Device::GetIntrinsics(const Stream &stream) const {
|
||||
bool ok;
|
||||
return GetIntrinsics(stream, &ok);
|
||||
}
|
||||
|
||||
Extrinsics Device::GetExtrinsics(const Stream &from, const Stream &to) const {
|
||||
bool ok;
|
||||
return GetExtrinsics(from, to, &ok);
|
||||
}
|
||||
|
||||
MotionIntrinsics Device::GetMotionIntrinsics() const {
|
||||
bool ok;
|
||||
return GetMotionIntrinsics(&ok);
|
||||
}
|
||||
|
||||
Extrinsics Device::GetMotionExtrinsics(const Stream &from) const {
|
||||
bool ok;
|
||||
return GetMotionExtrinsics(from, &ok);
|
||||
}
|
||||
|
||||
Intrinsics Device::GetIntrinsics(const Stream &stream, bool *ok) const {
|
||||
try {
|
||||
*ok = true;
|
||||
return stream_intrinsics_.at(stream);
|
||||
} catch (const std::out_of_range &e) {
|
||||
*ok = false;
|
||||
LOG(WARNING) << "Intrinsics of " << stream << " not found";
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Extrinsics Device::GetExtrinsics(const Stream &from, const Stream &to) const {
|
||||
Extrinsics Device::GetExtrinsics(
|
||||
const Stream &from, const Stream &to, bool *ok) const {
|
||||
try {
|
||||
*ok = true;
|
||||
return stream_from_extrinsics_.at(from).at(to);
|
||||
} catch (const std::out_of_range &e) {
|
||||
try {
|
||||
*ok = true;
|
||||
return stream_from_extrinsics_.at(to).at(from).Inverse();
|
||||
} catch (const std::out_of_range &e) {
|
||||
*ok = false;
|
||||
LOG(WARNING) << "Extrinsics from " << from << " to " << to
|
||||
<< " not found";
|
||||
return {};
|
||||
|
@ -220,19 +246,23 @@ Extrinsics Device::GetExtrinsics(const Stream &from, const Stream &to) const {
|
|||
}
|
||||
}
|
||||
|
||||
MotionIntrinsics Device::GetMotionIntrinsics() const {
|
||||
MotionIntrinsics Device::GetMotionIntrinsics(bool *ok) const {
|
||||
if (motion_intrinsics_) {
|
||||
*ok = true;
|
||||
return *motion_intrinsics_;
|
||||
} else {
|
||||
*ok = false;
|
||||
LOG(WARNING) << "Motion intrinsics not found";
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Extrinsics Device::GetMotionExtrinsics(const Stream &from) const {
|
||||
Extrinsics Device::GetMotionExtrinsics(const Stream &from, bool *ok) const {
|
||||
try {
|
||||
*ok = true;
|
||||
return motion_from_extrinsics_.at(from);
|
||||
} catch (const std::out_of_range &e) {
|
||||
*ok = false;
|
||||
LOG(WARNING) << "Motion extrinsics from " << from << " not found";
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -140,6 +140,24 @@ class MYNTEYE_API Device {
|
|||
*/
|
||||
Extrinsics GetMotionExtrinsics(const Stream &from) const;
|
||||
|
||||
/**
|
||||
* Get the intrinsics of stream.
|
||||
*/
|
||||
Intrinsics GetIntrinsics(const Stream &stream, bool *ok) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to another.
|
||||
*/
|
||||
Extrinsics GetExtrinsics(
|
||||
const Stream &from, const Stream &to, bool *ok) const;
|
||||
/**
|
||||
* Get the intrinsics of motion.
|
||||
*/
|
||||
MotionIntrinsics GetMotionIntrinsics(bool *ok) const;
|
||||
/**
|
||||
* Get the extrinsics from one stream to motion.
|
||||
*/
|
||||
Extrinsics GetMotionExtrinsics(const Stream &from, bool *ok) const;
|
||||
|
||||
/**
|
||||
* Set the intrinsics of stream.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user