feat(*): add depth resize

This commit is contained in:
kalman 2019-03-15 17:10:52 +08:00
parent 189a2bd6b7
commit 620b834b6c
8 changed files with 70 additions and 15 deletions

View File

@ -424,6 +424,7 @@ struct MYNTEYE_API IntrinsicsBase {
calib_model_ = CalibrationModel::UNKNOW; calib_model_ = CalibrationModel::UNKNOW;
} }
virtual ~IntrinsicsBase() {} virtual ~IntrinsicsBase() {}
virtual void ResizeIntrinsics() {}
/** The calibration model */ /** The calibration model */
CalibrationModel calib_model() const { CalibrationModel calib_model() const {
@ -433,7 +434,8 @@ struct MYNTEYE_API IntrinsicsBase {
std::uint16_t width; std::uint16_t width;
/** The height of the image in pixels */ /** The height of the image in pixels */
std::uint16_t height; std::uint16_t height;
/** Resize scale */
double resize_scale = 1.0;
protected: protected:
CalibrationModel calib_model_; CalibrationModel calib_model_;
}; };
@ -449,6 +451,14 @@ struct MYNTEYE_API IntrinsicsPinhole : public IntrinsicsBase {
IntrinsicsPinhole() { IntrinsicsPinhole() {
calib_model_ = CalibrationModel::PINHOLE; calib_model_ = CalibrationModel::PINHOLE;
} }
void ResizeIntrinsics() {
width = static_cast<std::uint16_t>(width * resize_scale);
height = static_cast<std::uint16_t>(height * resize_scale);
fx *= resize_scale;
fy *= resize_scale;
cx *= resize_scale;
cy *= resize_scale;
}
/** The focal length of the image plane, as a multiple of pixel width */ /** The focal length of the image plane, as a multiple of pixel width */
double fx; double fx;
/** The focal length of the image plane, as a multiple of pixel height */ /** The focal length of the image plane, as a multiple of pixel height */
@ -481,6 +491,14 @@ struct MYNTEYE_API IntrinsicsEquidistant : public IntrinsicsBase {
} }
/** The distortion coefficients: k2,k3,k4,k5,mu,mv,u0,v0 */ /** The distortion coefficients: k2,k3,k4,k5,mu,mv,u0,v0 */
double coeffs[8]; double coeffs[8];
void ResizeIntrinsics() {
width = static_cast<std::uint16_t>(width * resize_scale);
height = static_cast<std::uint16_t>(height * resize_scale);
coeffs[4] *= resize_scale;
coeffs[5] *= resize_scale;
coeffs[6] *= resize_scale;
coeffs[7] *= resize_scale;
}
}; };
MYNTEYE_API MYNTEYE_API

View File

@ -25,11 +25,22 @@ int main(int argc, char *argv[]) {
auto &&request = api->SelectStreamRequest(&ok); auto &&request = api->SelectStreamRequest(&ok);
if (!ok) return 1; if (!ok) return 1;
api->ConfigStreamRequest(request); api->ConfigStreamRequest(request);
auto in_left = api->GetIntrinsicsBase(Stream::LEFT);
LOG(INFO) << "Intrinsics left: {" << *api->GetIntrinsicsBase(Stream::LEFT) auto in_right = api->GetIntrinsicsBase(Stream::RIGHT);
<< "}"; if (in_left->calib_model() == CalibrationModel::PINHOLE) {
LOG(INFO) << "Intrinsics right: {" << *api->GetIntrinsicsBase(Stream::RIGHT) in_left = std::dynamic_pointer_cast<IntrinsicsPinhole>(in_left);
<< "}"; in_right = std::dynamic_pointer_cast<IntrinsicsPinhole>(in_right);
} else if (in_left->calib_model() == CalibrationModel::KANNALA_BRANDT) {
in_left = std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_left);
in_right = std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_right);
} else {
LOG(INFO) << "UNKNOW CALIB MODEL.";
return 0;
}
in_left -> ResizeIntrinsics();
in_right -> ResizeIntrinsics();
LOG(INFO) << "Intrinsics left: {" << *in_left << "}";
LOG(INFO) << "Intrinsics right: {" << *in_right << "}";
LOG(INFO) << "Extrinsics right to left: {" LOG(INFO) << "Extrinsics right to left: {"
<< api->GetExtrinsics(Stream::RIGHT, Stream::LEFT) << "}"; << api->GetExtrinsics(Stream::RIGHT, Stream::LEFT) << "}";

View File

@ -335,6 +335,8 @@ void RectifyProcessor::InitParams(
IntrinsicsEquidistant in_right, IntrinsicsEquidistant in_right,
Extrinsics ex_right_to_left) { Extrinsics ex_right_to_left) {
calib_model = CalibrationModel::KANNALA_BRANDT; calib_model = CalibrationModel::KANNALA_BRANDT;
in_left.ResizeIntrinsics();
in_right.ResizeIntrinsics();
camodocal::CameraPtr camera_odo_ptr_left = camodocal::CameraPtr camera_odo_ptr_left =
generateCameraFromIntrinsicsEquidistant(in_left); generateCameraFromIntrinsicsEquidistant(in_left);
camodocal::CameraPtr camera_odo_ptr_right = camodocal::CameraPtr camera_odo_ptr_right =

View File

@ -80,6 +80,8 @@ void RectifyProcessorOCV::InitParams(
IntrinsicsPinhole in_right, IntrinsicsPinhole in_right,
Extrinsics ex_right_to_left) { Extrinsics ex_right_to_left) {
calib_model = CalibrationModel::PINHOLE; calib_model = CalibrationModel::PINHOLE;
in_left.ResizeIntrinsics();
in_right.ResizeIntrinsics();
cv::Size size{in_left.width, in_left.height}; cv::Size size{in_left.width, in_left.height};
cv::Mat M1 = cv::Mat M1 =

View File

@ -483,7 +483,7 @@ bool Channels::GetFiles(
if (imu_params->ok) { if (imu_params->ok) {
auto &&n = file_channel_.GetImuParamsFromData( auto &&n = file_channel_.GetImuParamsFromData(
data + i, file_size, imu_params); data + i, file_size, imu_params);
CHECK_EQ(n, file_size); // CHECK_EQ(n, file_size);
} }
} break; } break;
default: default:

View File

@ -656,7 +656,18 @@ void Device::UpdateStreamIntrinsics(
img_res.height == request.GetResolution().height && img_res.height == request.GetResolution().height &&
img_res.width == request.GetResolution().width / 2; img_res.width == request.GetResolution().width / 2;
} else if (capability == Capabilities::STEREO) { } else if (capability == Capabilities::STEREO) {
ok = img_params.ok && img_res == request.GetResolution(); if (img_res == request.GetResolution()) {
ok = img_params.ok;
} else if (request.GetResolution().height / img_res.height ==
request.GetResolution().width / img_res.width) {
double scale = static_cast<double> (
1.0 * request.GetResolution().height / img_res.height);
img_params.in_left->resize_scale = scale;
img_params.in_right->resize_scale = scale;
ok = img_params.ok;
} else {
ok = false;
}
} }
if (ok) { if (ok) {
SetIntrinsics(Stream::LEFT, img_params.in_left); SetIntrinsics(Stream::LEFT, img_params.in_left);

View File

@ -54,7 +54,14 @@
<!-- MYNTEYE-S2100/S2000/S210A, Reslution: 2560x800, Format: YUYV/BGR888, Fps: 30 --> <!-- MYNTEYE-S2100/S2000/S210A, Reslution: 2560x800, Format: YUYV/BGR888, Fps: 30 -->
<arg name="index_s2_6" default="6" /> <arg name="index_s2_6" default="6" />
<arg name="request_index" default="$(arg index_s2_2)" /> <arg name="standard2/request_index" default="$(arg index_s2_2)" />
<!-- MYNTEYE-S1030, Reslution: 752x480, Format: YUYV -->
<arg name="index_s_0" default="0" />
<!-- MYNTEYE-S1030, Reslution: 376x240, Format: YUYV -->
<arg name="index_s_1" default="1" />
<arg name="standard/request_index" default="$(arg index_s_0)" />
<!-- disparity computing method type --> <!-- disparity computing method type -->
<arg name="sgbm" default="0" /> <arg name="sgbm" default="0" />
@ -259,7 +266,8 @@
<param name="enable_depth" value="$(arg enable_depth)" /> <param name="enable_depth" value="$(arg enable_depth)" />
<!-- stream request index --> <!-- stream request index -->
<param name="request_index" value="$(arg request_index)" /> <param name="standard/request_index" value="$(arg standard/request_index)" />
<param name="standard2/request_index" value="$(arg standard2/request_index)" />
<!-- device options of standard--> <!-- device options of standard-->

View File

@ -1062,7 +1062,7 @@ class ROSWrapperNodelet : public nodelet::Nodelet {
model_ = api_->GetModel(); model_ = api_->GetModel();
if (model_ == Model::STANDARD2 || model_ == Model::STANDARD210A) { if (model_ == Model::STANDARD2 || model_ == Model::STANDARD210A) {
private_nh_.getParam("request_index", request_index); private_nh_.getParam("standard2/request_index", request_index);
switch (request_index) { switch (request_index) {
case 0: case 0:
case 4: case 4:
@ -1082,7 +1082,7 @@ class ROSWrapperNodelet : public nodelet::Nodelet {
} }
} }
if (model_ == Model::STANDARD) { if (model_ == Model::STANDARD) {
request_index = 0; private_nh_.getParam("standard/request_index", request_index);
frame_rate_ = api_->GetOptionValue(Option::FRAME_RATE); frame_rate_ = api_->GetOptionValue(Option::FRAME_RATE);
} }
@ -1217,11 +1217,12 @@ class ROSWrapperNodelet : public nodelet::Nodelet {
} }
camera_info->header.frame_id = frame_ids_[stream]; camera_info->header.frame_id = frame_ids_[stream];
camera_info->width = in_base->width;
camera_info->height = in_base->height;
if (in_base->calib_model() == CalibrationModel::PINHOLE) { if (in_base->calib_model() == CalibrationModel::PINHOLE) {
auto in = std::dynamic_pointer_cast<IntrinsicsPinhole>(in_base); auto in = std::dynamic_pointer_cast<IntrinsicsPinhole>(in_base);
in -> ResizeIntrinsics();
camera_info->width = in_base->width;
camera_info->height = in_base->height;
// [fx 0 cx] // [fx 0 cx]
// K = [ 0 fy cy] // K = [ 0 fy cy]
// [ 0 0 1] // [ 0 0 1]
@ -1253,7 +1254,9 @@ class ROSWrapperNodelet : public nodelet::Nodelet {
} }
} else if (in_base->calib_model() == CalibrationModel::KANNALA_BRANDT) { } else if (in_base->calib_model() == CalibrationModel::KANNALA_BRANDT) {
auto in = std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_base); auto in = std::dynamic_pointer_cast<IntrinsicsEquidistant>(in_base);
in -> ResizeIntrinsics();
camera_info->width = in_base->width;
camera_info->height = in_base->height;
camera_info->distortion_model = "kannala_brandt"; camera_info->distortion_model = "kannala_brandt";
// coeffs: k2,k3,k4,k5,mu,mv,u0,v0 // coeffs: k2,k3,k4,k5,mu,mv,u0,v0