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
......@@ -32,6 +32,7 @@ enum struct Channel : int {
Support2 = 14, // 8UC4 (currently)
Segmentation = 15, // 32S?
ColourNormals = 16, // 8UC4
ColourHighRes = 20, // 8UC3 or 8UC4
AudioLeft = 32,
AudioRight = 33,
......
......@@ -211,6 +211,26 @@ void Calibrate::_updateIntrinsics() {
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) {
// cv::cuda::remap() can not use same Mat for input and output
......
......@@ -55,6 +55,10 @@ class Calibrate : public ftl::Configurable {
*/
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 &getCameraMatrixRight() { return Kr_; }
const cv::Mat &getCameraMatrix() { return getCameraMatrixLeft(); }
......
......@@ -96,7 +96,7 @@ void StereoVideoSource::init(const string &file) {
if (!calib_->isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!";
// Generate camera parameters from camera matrix
cv::Mat K = calib_->getCameraMatrix();
cv::Mat K = calib_->getCameraMatrixLeft(depth_size_);
params_ = {
K.at<double>(0,0), // Fx
K.at<double>(1,1), // Fy
......@@ -152,7 +152,7 @@ void StereoVideoSource::init(const string &file) {
ftl::rgbd::Camera StereoVideoSource::parameters(Channel chan) {
if (chan == Channel::Right) {
cv::Mat q = calib_->getCameraMatrixRight();
cv::Mat q = calib_->getCameraMatrixRight(depth_size_);
ftl::rgbd::Camera params = {
q.at<double>(0,0), // Fx
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