Skip to content
Snippets Groups Projects
Commit 5eb7ef3e authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

camera matrix scaling

parent e2f8c986
No related branches found
No related tags found
1 merge request!196High resolution colour
Pipeline #16771 failed
This commit is part of merge request !196. Comments created here will be created in the context of that merge request.
...@@ -8,30 +8,31 @@ namespace ftl { ...@@ -8,30 +8,31 @@ namespace ftl {
namespace codecs { namespace codecs {
enum struct Channel : int { enum struct Channel : int {
None = -1, None = -1,
Colour = 0, // 8UC3 or 8UC4 Colour = 0, // 8UC3 or 8UC4
Left = 0, Left = 0,
Depth = 1, // 32S or 32F Depth = 1, // 32S or 32F
Right = 2, // 8UC3 or 8UC4 Right = 2, // 8UC3 or 8UC4
Colour2 = 2, Colour2 = 2,
Disparity = 3, Disparity = 3,
Depth2 = 3, Depth2 = 3,
Deviation = 4, Deviation = 4,
Screen = 4, Screen = 4,
Normals = 5, // 32FC4 Normals = 5, // 32FC4
Points = 6, // 32FC4 (should be deprecated) Points = 6, // 32FC4 (should be deprecated)
Confidence = 7, // 32F Confidence = 7, // 32F
Contribution = 7, // 32F Contribution = 7, // 32F
EnergyVector = 8, // 32FC4 EnergyVector = 8, // 32FC4
Flow = 9, // 32F Flow = 9, // 32F
Smoothing = 9, // 32F Smoothing = 9, // 32F
Energy = 10, // 32F Energy = 10, // 32F
Mask = 11, // 32U Mask = 11, // 32U
Density = 12, // 32F Density = 12, // 32F
Support1 = 13, // 8UC4 (currently) Support1 = 13, // 8UC4 (currently)
Support2 = 14, // 8UC4 (currently) Support2 = 14, // 8UC4 (currently)
Segmentation = 15, // 32S? Segmentation = 15, // 32S?
ColourNormals = 16, // 8UC4 ColourNormals = 16, // 8UC4
ColourHighRes = 20, // 8UC3 or 8UC4
AudioLeft = 32, AudioLeft = 32,
AudioRight = 33, AudioRight = 33,
...@@ -39,7 +40,7 @@ enum struct Channel : int { ...@@ -39,7 +40,7 @@ enum struct Channel : int {
Configuration = 64, // JSON Data Configuration = 64, // JSON Data
Calibration = 65, // Camera Parameters Object Calibration = 65, // Camera Parameters Object
Pose = 66, // Eigen::Matrix4d Pose = 66, // Eigen::Matrix4d
Index = 67, Index = 67,
Data = 2048 // Custom data, any codec. Data = 2048 // Custom data, any codec.
}; };
...@@ -51,7 +52,7 @@ std::string name(Channel c); ...@@ -51,7 +52,7 @@ std::string name(Channel c);
int type(Channel c); int type(Channel c);
class Channels { class Channels {
public: public:
class iterator { class iterator {
public: public:
...@@ -67,48 +68,48 @@ class Channels { ...@@ -67,48 +68,48 @@ class Channels {
unsigned int ix_; unsigned int ix_;
}; };
inline Channels() { mask = 0; } inline Channels() { mask = 0; }
inline explicit Channels(unsigned int m) { mask = m; } inline explicit Channels(unsigned int m) { mask = m; }
inline explicit Channels(Channel c) { mask = (c == Channel::None) ? 0 : 0x1 << static_cast<unsigned int>(c); } inline explicit Channels(Channel c) { mask = (c == Channel::None) ? 0 : 0x1 << static_cast<unsigned int>(c); }
inline Channels &operator=(Channel c) { mask = (c == Channel::None) ? 0 : 0x1 << static_cast<unsigned int>(c); return *this; } inline Channels &operator=(Channel c) { mask = (c == Channel::None) ? 0 : 0x1 << static_cast<unsigned int>(c); return *this; }
inline Channels operator|(Channel c) const { return (c == Channel::None) ? Channels(mask) : Channels(mask | (0x1 << static_cast<unsigned int>(c))); } inline Channels operator|(Channel c) const { return (c == Channel::None) ? Channels(mask) : Channels(mask | (0x1 << static_cast<unsigned int>(c))); }
inline Channels operator+(Channel c) const { return (c == Channel::None) ? Channels(mask) : Channels(mask | (0x1 << static_cast<unsigned int>(c))); } inline Channels operator+(Channel c) const { return (c == Channel::None) ? Channels(mask) : Channels(mask | (0x1 << static_cast<unsigned int>(c))); }
inline Channels &operator|=(Channel c) { mask |= (c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c)); return *this; } inline Channels &operator|=(Channel c) { mask |= (c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c)); return *this; }
inline Channels &operator+=(Channel c) { mask |= (c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c)); return *this; } inline Channels &operator+=(Channel c) { mask |= (c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c)); return *this; }
inline Channels &operator-=(Channel c) { mask &= ~((c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c))); return *this; } inline Channels &operator-=(Channel c) { mask &= ~((c == Channel::None) ? 0 : (0x1 << static_cast<unsigned int>(c))); return *this; }
inline Channels &operator+=(unsigned int c) { mask |= (0x1 << c); return *this; } inline Channels &operator+=(unsigned int c) { mask |= (0x1 << c); return *this; }
inline Channels &operator-=(unsigned int c) { mask &= ~(0x1 << c); return *this; } inline Channels &operator-=(unsigned int c) { mask &= ~(0x1 << c); return *this; }
inline bool has(Channel c) const { inline bool has(Channel c) const {
return (c == Channel::None) ? true : mask & (0x1 << static_cast<unsigned int>(c)); return (c == Channel::None) ? true : mask & (0x1 << static_cast<unsigned int>(c));
} }
inline bool has(unsigned int c) const { inline bool has(unsigned int c) const {
return mask & (0x1 << c); return mask & (0x1 << c);
} }
inline iterator begin() { return iterator(*this, 0); } inline iterator begin() { return iterator(*this, 0); }
inline iterator end() { return iterator(*this, 32); } inline iterator end() { return iterator(*this, 32); }
inline operator unsigned int() { return mask; } inline operator unsigned int() { return mask; }
inline operator bool() { return mask > 0; } inline operator bool() { return mask > 0; }
inline operator Channel() { inline operator Channel() {
if (mask == 0) return Channel::None; if (mask == 0) return Channel::None;
int ix = 0; int ix = 0;
int tmask = mask; int tmask = mask;
while (!(tmask & 0x1) && ++ix < 32) tmask >>= 1; while (!(tmask & 0x1) && ++ix < 32) tmask >>= 1;
return static_cast<Channel>(ix); return static_cast<Channel>(ix);
} }
inline size_t count() { return std::bitset<32>(mask).count(); } inline size_t count() { return std::bitset<32>(mask).count(); }
inline void clear() { mask = 0; } inline void clear() { mask = 0; }
static const size_t kMax = 32; static const size_t kMax = 32;
static Channels All(); static Channels All();
private: private:
unsigned int mask; unsigned int mask;
}; };
inline Channels::iterator Channels::iterator::operator++() { Channels::iterator i = *this; while (++ix_ < 32 && !channels_.has(ix_)); return i; } inline Channels::iterator Channels::iterator::operator++() { Channels::iterator i = *this; while (++ix_ < 32 && !channels_.has(ix_)); return i; }
...@@ -124,9 +125,9 @@ static const Channels kAllChannels(0xFFFFFFFFu); ...@@ -124,9 +125,9 @@ static const Channels kAllChannels(0xFFFFFFFFu);
inline bool isFloatChannel(ftl::codecs::Channel chan) { inline bool isFloatChannel(ftl::codecs::Channel chan) {
switch (chan) { switch (chan) {
case Channel::Depth : case Channel::Depth :
//case Channel::Normals : //case Channel::Normals :
case Channel::Confidence: case Channel::Confidence:
case Channel::Flow : case Channel::Flow :
case Channel::Density: case Channel::Density:
case Channel::Energy : return true; case Channel::Energy : return true;
default : return false; default : return false;
...@@ -139,11 +140,11 @@ inline bool isFloatChannel(ftl::codecs::Channel chan) { ...@@ -139,11 +140,11 @@ inline bool isFloatChannel(ftl::codecs::Channel chan) {
MSGPACK_ADD_ENUM(ftl::codecs::Channel); MSGPACK_ADD_ENUM(ftl::codecs::Channel);
inline ftl::codecs::Channels operator|(ftl::codecs::Channel a, ftl::codecs::Channel b) { inline ftl::codecs::Channels operator|(ftl::codecs::Channel a, ftl::codecs::Channel b) {
return ftl::codecs::Channels(a) | b; return ftl::codecs::Channels(a) | b;
} }
inline ftl::codecs::Channels operator+(ftl::codecs::Channel a, ftl::codecs::Channel b) { inline ftl::codecs::Channels operator+(ftl::codecs::Channel a, ftl::codecs::Channel b) {
return ftl::codecs::Channels(a) | b; return ftl::codecs::Channels(a) | b;
} }
#endif // _FTL_RGBD_CHANNELS_HPP_ #endif // _FTL_RGBD_CHANNELS_HPP_
...@@ -211,6 +211,26 @@ void Calibrate::_updateIntrinsics() { ...@@ -211,6 +211,26 @@ void Calibrate::_updateIntrinsics() {
map2_gpu_.second.upload(map2_.second); map2_gpu_.second.upload(map2_.second);
} }
cv::Mat Calibrate::getCameraMatrixLeft(const cv::Size res) {
double scale_x = ((double) res.width) / ((double) img_size_.width);
double scale_y = ((double) res.height) / ((double) img_size_.height);
Mat scale(cv::Size(3, 3), CV_64F, 0.0);
scale.at<double>(0, 0) = scale_x;
scale.at<double>(1, 1) = scale_y;
scale.at<double>(2, 2) = 1.0;
return scale * Kl_;
}
cv::Mat Calibrate::getCameraMatrixRight(const cv::Size res) {
double scale_x = ((double) res.width) / ((double) img_size_.width);
double scale_y = ((double) res.height) / ((double) img_size_.height);
Mat scale(cv::Size(3, 3), CV_64F, 0.0);
scale.at<double>(0, 0) = scale_x;
scale.at<double>(1, 1) = scale_y;
scale.at<double>(2, 2) = 1.0;
return scale * Kr_;
}
void Calibrate::rectifyStereo(GpuMat &l, GpuMat &r, Stream &stream) { void Calibrate::rectifyStereo(GpuMat &l, GpuMat &r, Stream &stream) {
// cv::cuda::remap() can not use same Mat for input and output // cv::cuda::remap() can not use same Mat for input and output
......
...@@ -55,6 +55,10 @@ class Calibrate : public ftl::Configurable { ...@@ -55,6 +55,10 @@ class Calibrate : public ftl::Configurable {
*/ */
const cv::Mat &getQ() const { return Q_; } const cv::Mat &getQ() const { return Q_; }
cv::Mat getCameraMatrixLeft(const cv::Size res);
cv::Mat getCameraMatrixRight(const cv::Size res);
// TODO: Remove. Always require resolution for correct scaling
const cv::Mat &getCameraMatrixLeft() { return Kl_; } const cv::Mat &getCameraMatrixLeft() { return Kl_; }
const cv::Mat &getCameraMatrixRight() { return Kr_; } const cv::Mat &getCameraMatrixRight() { return Kr_; }
const cv::Mat &getCameraMatrix() { return getCameraMatrixLeft(); } const cv::Mat &getCameraMatrix() { return getCameraMatrixLeft(); }
......
...@@ -96,7 +96,7 @@ void StereoVideoSource::init(const string &file) { ...@@ -96,7 +96,7 @@ void StereoVideoSource::init(const string &file) {
if (!calib_->isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!"; if (!calib_->isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!";
// Generate camera parameters from camera matrix // Generate camera parameters from camera matrix
cv::Mat K = calib_->getCameraMatrix(); cv::Mat K = calib_->getCameraMatrixLeft(depth_size_);
params_ = { params_ = {
K.at<double>(0,0), // Fx K.at<double>(0,0), // Fx
K.at<double>(1,1), // Fy K.at<double>(1,1), // Fy
...@@ -152,7 +152,7 @@ void StereoVideoSource::init(const string &file) { ...@@ -152,7 +152,7 @@ void StereoVideoSource::init(const string &file) {
ftl::rgbd::Camera StereoVideoSource::parameters(Channel chan) { ftl::rgbd::Camera StereoVideoSource::parameters(Channel chan) {
if (chan == Channel::Right) { if (chan == Channel::Right) {
cv::Mat q = calib_->getCameraMatrixRight(); cv::Mat q = calib_->getCameraMatrixRight(depth_size_);
ftl::rgbd::Camera params = { ftl::rgbd::Camera params = {
q.at<double>(0,0), // Fx q.at<double>(0,0), // Fx
q.at<double>(1,1), // Fy q.at<double>(1,1), // Fy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment