fix(src): Determine the default intrinsics based on the resulution

This commit is contained in:
Osenberg
2019-08-06 20:04:38 +08:00
parent 1cda60d137
commit 2260f5c582
11 changed files with 128 additions and 225 deletions

View File

@@ -89,4 +89,80 @@ stream_requests_map = {
}
};
/**
* default intrinsics
*/
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics() {
auto res = std::make_shared<IntrinsicsPinhole>();
res->width = 640;
res->height = 400;
res->model = 0;
res->fx = 3.6220059643202876e+02;
res->fy = 3.6350065250745848e+02;
res->cx = 4.0658699068023441e+02;
res->cy = 2.3435161110061483e+02;
double codffs[5] = {
-2.5034765682756088e-01,
5.0579399202897619e-02,
-7.0536676161976066e-04,
-8.5255451307033846e-03,
0.
};
for (unsigned int i = 0; i < 5; i++) {
res->coeffs[i] = codffs[i];
}
return res;
}
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics(const Resolution &resolution) {
auto res = getDefaultIntrinsics();
res->resize_scale = static_cast<double>(resolution.width / res->width);
res->ResizeIntrinsics();
return res;
}
std::shared_ptr<Extrinsics> getDefaultExtrinsics() {
auto res = std::make_shared<Extrinsics>();
double rotation[9] = {
9.9867908939669447e-01, -6.3445566137485428e-03, 5.0988459509619687e-02,
5.9890316389333252e-03, 9.9995670037792639e-01, 7.1224201868366971e-03,
-5.1031440326695092e-02, -6.8076406092671274e-03, 9.9867384471984544e-01
};
double translation[3] = {-1.2002489764113250e+02, -1.1782637409050747e+00,
-5.2058205159996538e+00};
for (unsigned int i = 0; i < 3; i++) {
for (unsigned int j = 0; j < 3; j++) {
res->rotation[i][j] = rotation[i*3 + j];
}
}
for (unsigned int i = 0; i < 3; i++) {
res->translation[i] = translation[i];
}
return res;
}
// sgbm_matcher = cv::StereoSGBM::create(0, 16, 3);
// sgbm_matcher->setPreFilterCap(63);
// sgbm_matcher->setBlockSize(sgbmWinSize);
// sgbm_matcher->setP1(8 * sgbmWinSize * sgbmWinSize);
// sgbm_matcher->setP2(32 * sgbmWinSize * sgbmWinSize);
// sgbm_matcher->setMinDisparity(0);
// sgbm_matcher->setNumDisparities(numberOfDisparities);
// sgbm_matcher->setUniquenessRatio(10);
// sgbm_matcher->setSpeckleWindowSize(100);
// sgbm_matcher->setSpeckleRange(32);
// sgbm_matcher->setDisp12MaxDiff(1);
// bm_matcher = cv::StereoBM::create(0, 3);
// bm_matcher->setPreFilterSize(9);
// bm_matcher->setPreFilterCap(31);
// bm_matcher->setBlockSize(15);
// bm_matcher->setMinDisparity(0);
// bm_matcher->setNumDisparities(64);
// bm_matcher->setUniquenessRatio(60);
// bm_matcher->setTextureThreshold(10);
// bm_matcher->setSpeckleWindowSize(100);
// bm_matcher->setSpeckleRange(4);
MYNTEYE_END_NAMESPACE

View File

@@ -18,6 +18,7 @@
#include <map>
#include <set>
#include <vector>
#include <memory>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
@@ -37,6 +38,14 @@ using StreamRequests = std::vector<StreamRequest>;
extern const std::map<Model, std::map<Capabilities, StreamRequests>>
stream_requests_map;
const std::vector<Resolution> resolution_list = {{640, 400},
{1280, 800}};
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics();
std::shared_ptr<IntrinsicsBase> getDefaultIntrinsics(const Resolution &resolution);
std::shared_ptr<Extrinsics> getDefaultExtrinsics();
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEVICE_CONFIG_H_

View File

@@ -89,7 +89,8 @@ Device::Device(const Model &model,
device_(device),
streams_(std::make_shared<Streams>(streams_adapter)),
channels_(std::make_shared<Channels>(device_, channels_adapter)),
motions_(std::make_shared<Motions>(channels_)) {
motions_(std::make_shared<Motions>(channels_)),
is_default_intrinsics_(false) {
VLOG(2) << __func__;
ReadAllInfos();
}
@@ -612,11 +613,28 @@ void Device::ReadAllInfos() {
motions_->SetDeviceInfo(device_info_);
bool img_params_ok = false;
if (all_img_params_.empty()) {
is_default_intrinsics_ = true;
LOG(ERROR) << "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.";
LOG(WARNING) << "Intrinsics & extrinsics not exist. Use default intrinsics.";
LOG(INFO) << "camera calib model: unknow, use default pinhole data";
auto spec_string = device_info_->spec_version.to_string();
for (auto &&resolution : resolution_list) {
all_img_params_[resolution] = {
true, spec_string, getDefaultIntrinsics(resolution),
getDefaultIntrinsics(resolution), *getDefaultExtrinsics()};
}
}
for (auto &&params : all_img_params_) {
auto &&img_params = params.second;
if (img_params.ok) {
img_params_ok = true;
SetIntrinsics(Stream::LEFT, img_params.in_left);
SetIntrinsics(Stream::RIGHT, img_params.in_right);
SetExtrinsics(Stream::RIGHT, Stream::LEFT, img_params.ex_right_to_left);
@@ -627,9 +645,6 @@ void Device::ReadAllInfos() {
break;
}
}
if (!img_params_ok) {
LOG(WARNING) << "Intrinsics & extrinsics not exist";
}
if (imu_params.ok) {
imu_params_ = imu_params;
@@ -726,4 +741,8 @@ void Device::EnableProcessMode(const std::int32_t& mode) {
motions_->EnableProcessMode(mode);
}
bool Device::CheckImageParams() {
return is_default_intrinsics_;
}
MYNTEYE_END_NAMESPACE