refactor(intrinsics): adjust intrinsics types

This commit is contained in:
John Zhao 2019-01-04 11:42:24 +08:00
parent 611468ad90
commit 938dc08654
5 changed files with 70 additions and 107 deletions

View File

@ -190,6 +190,11 @@ class MYNTEYE_API API {
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the intrinsics of stream.
*/
template<typename T>
T GetIntrinsics(const Stream &from) const;
/**
* Get the extrinsics from one stream to another.
*/
@ -202,11 +207,6 @@ class MYNTEYE_API API {
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
/**
* Get the intrinsics of stream.
*/
template<typename T>
T GetIntrinsics(const Stream &from) const;
/**
* Log all option infos.
@ -315,13 +315,6 @@ T API::GetIntrinsics(const Stream &from) const {
return device_->GetIntrinsics<T>(from);
}
template <typename T>
T Device::GetIntrinsics(const Stream &from) const {
T res;
printf("type %d\n", res.calib_model_);
return res;
}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_API_API_H_

View File

@ -154,6 +154,11 @@ class MYNTEYE_API Device {
* Get the intrinsics of stream.
*/
Intrinsics GetIntrinsics(const Stream &stream) const;
/**
* Get the intrinsics of stream.
*/
template<typename T>
T GetIntrinsics(const Stream &from) const;
/**
* Get the extrinsics from one stream to another.
*/
@ -203,12 +208,6 @@ class MYNTEYE_API Device {
*/
void SetMotionExtrinsics(const Stream &from, const Extrinsics &ex);
/**
* Get the intrinsics of stream.
*/
template<typename T>
T GetIntrinsics(const Stream &from) const;
/**
* Log all option infos.
*/
@ -366,6 +365,13 @@ class MYNTEYE_API Device {
friend tools::DeviceWriter;
};
template <typename T>
T Device::GetIntrinsics(const Stream &from) const {
T res;
printf("type %d\n", res.calib_model_);
return res;
}
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEVICE_DEVICE_H_

View File

@ -395,32 +395,35 @@ std::ostream &operator<<(std::ostream &os, const StreamRequest &request);
* @brief Intrinsic and extrinsic properties.
*/
/** different model of camera calibration */
typedef enum CalibrationModel {
/** pinhole camera */
CALIB_MODEL_PINHOLE = 0,
/** equidistant camera */
CALIB_MODEL_KANNALA_BRANDT = 1,
CALIB_MODEL_UNKNOW,
/**
* @ingroup calibration
* Camera calibration model.
*/
enum class CalibrationModel : std::uint8_t {
/** Unknow */
CALIB_MODEL_UNKNOW = 0,
/** Pinhole */
CALIB_MODEL_PINHOLE = 1,
/** Equidistant: KANNALA_BRANDT */
CALIB_MODEL_KANNALA_BRANDT = 2,
// CALIB_MODEL_SCARAMUZZA,
// CALIB_MODEL_MEI
}CALIB_MODEL;
// CALIB_MODEL_MEI,
};
struct MYNTEYE_API IntrinsicsBase {
IntrinsicsBase() {
calib_model = CalibrationModel::CALIB_MODEL_UNKNOW;
}
CalibrationModel calib_model;
};
/**
* @ingroup calibration
* Stream intrinsics,
* Stream intrinsics (Pinhole)
*/
struct MYNTEYE_API IntrinsicsBase {
IntrinsicsBase() {
calib_model_ = CALIB_MODEL_UNKNOW;
}
CALIB_MODEL calib_model_;
};
struct MYNTEYE_API Intrinsics : public IntrinsicsBase {
Intrinsics() {
calib_model_ = CALIB_MODEL_PINHOLE;
struct MYNTEYE_API IntrinsicsPinhole : public IntrinsicsBase {
IntrinsicsPinhole() {
calib_model = CalibrationModel::CALIB_MODEL_PINHOLE;
}
/** The width of the image in pixels */
std::uint16_t width;
@ -440,25 +443,22 @@ struct MYNTEYE_API Intrinsics : public IntrinsicsBase {
double coeffs[5];
};
/*
model_type: KANNALA_BRANDT
camera_name: KANNALA_BRANDT
image_width: 640
image_height: 400
projection_parameters:
k2: 4.9972342319338209e-01
k3: 4.3314206872885375e-01
k4: -9.2064699153680563e-01
k5: 4.1211925379358533e-01
mu: 2.0077513040612871e+02
mv: 2.0099851605062454e+02
u0: 3.1079403134153824e+02
v0: 2.1225649273618896e+02
*/
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const IntrinsicsPinhole &in);
struct MYNTEYE_API Intrinsics2 : public IntrinsicsBase {
Intrinsics2() {
calib_model_ = CALIB_MODEL_KANNALA_BRANDT;
/**
* @ingroup calibration
* Stream intrinsics (Pinhole)
*/
using Intrinsics = IntrinsicsPinhole;
/**
* @ingroup calibration
* Stream intrinsics (Equidistant: KANNALA_BRANDT)
*/
struct MYNTEYE_API IntrinsicsEquidistant : public IntrinsicsBase {
IntrinsicsEquidistant() {
calib_model = CalibrationModel::CALIB_MODEL_KANNALA_BRANDT;
}
/** The width of the image in pixels */
std::uint16_t width;
@ -475,33 +475,8 @@ struct MYNTEYE_API Intrinsics2 : public IntrinsicsBase {
double v0;
};
// union MYNTEYE_API CameraParameters {
// struct IntrinsicsBase intrinsics_base;
// struct Intrinsics intrinsics10;
// struct Intrinsics2 intrinsics20;
// unsigned char raw[];
// CameraParameters(struct IntrinsicsBase& base) {
// memset(raw, 0, sizeof(union CameraParameters));
// switch (base.calib_model_) {
// case CALIB_MODEL_10:
// intrinsics10 = static_cast<struct Intrinsics&>(base);
// break;
// case CALIB_MODEL_20:
// intrinsics20 = static_cast<struct Intrinsics2&>(base);
// break;
// default:
// // warning!!! no impl!!!
// intrinsics_base = base;
// return;
// }
// }
// CALIB_MODEL getModelType() {return intrinsics_base.calib_model_;}
// };
// MYNTEYE_API
// std::ostream &operator<<(std::ostream &os, const CameraParameters &in);
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const Intrinsics &in);
std::ostream &operator<<(std::ostream &os, const IntrinsicsEquidistant &in);
/**
* @ingroup calibration

View File

@ -31,28 +31,6 @@ int main(int argc, char *argv[]) {
<< "}";
LOG(INFO) << "Extrinsics right to left: {"
<< api->GetExtrinsics(Stream::RIGHT, Stream::LEFT) << "}";
auto inr = api->GetIntrinsics(Stream::LEFT);
// CameraParameters cmm(inr);
// for (int i = 0;i< sizeof(cmm) ; i++) {
// printf(" %x ",cmm.raw[i]);
// }
// printf("end: %d\n", (int)(cmm.getModelType()));
// Intrinsics2 xxx2;
// CameraParameters cmm2(xxx2);
// for (int i = 0;i< sizeof(cmm2) ; i++) {
// printf(" %x ",cmm2.raw[i]);
// }
// printf("end: %d\n", (int)(cmm2.getModelType()));
// IntrinsicsBase xxx3;
// CameraParameters cmm3(xxx3);
// for (int i = 0;i< sizeof(cmm3) ; i++) {
// printf(" %x ",cmm3.raw[i]);
// }
// printf("end: %d\n", (int)(cmm3.getModelType()));
api->GetIntrinsics<Intrinsics>(Stream::LEFT);
return 0;
}

View File

@ -188,8 +188,9 @@ std::ostream &operator<<(std::ostream &os, const StreamRequest &request) {
<< ", format: " << request.format << ", fps: " << request.fps;
}
std::ostream &operator<<(std::ostream &os, const Intrinsics &in) {
os << FULL_PRECISION << "width: " << in.width << ", height: " << in.height
std::ostream &operator<<(std::ostream &os, const IntrinsicsPinhole &in) {
os << "pinhole, " << FULL_PRECISION
<< "width: " << in.width << ", height: " << in.height
<< ", fx: " << in.fx << ", fy: " << in.fy << ", cx: " << in.cx
<< ", cy: " << in.cy << ", model: " << static_cast<int>(in.model)
<< ", coeffs: [";
@ -198,6 +199,16 @@ std::ostream &operator<<(std::ostream &os, const Intrinsics &in) {
return os << in.coeffs[4] << "]";
}
std::ostream &operator<<(std::ostream &os, const IntrinsicsEquidistant &in) {
os << "equidistant, " << FULL_PRECISION
<< "width: " << in.width << ", height: " << in.height
<< ", k2: " << in.k2 << ", k3: " << in.k3
<< ", k4: " << in.k4 << ", k5: " << in.k5
<< ", mu: " << in.mu << ", mv: " << in.mv
<< ", u0: " << in.u0 << ", v0: " << in.v0;
return os;
}
std::ostream &operator<<(std::ostream &os, const ImuIntrinsics &in) {
os << FULL_PRECISION << "scale: [";
for (int i = 0; i <= 2; i++)