Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task04 Артём Трубников СПбГУ #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/results/herzjesu2400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/results/saharov3201.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 12 additions & 14 deletions src/phg/core/calibration.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#include <phg/sfm/defines.h>
#include "calibration.h"

#include <phg/sfm/defines.h>

phg::Calibration::Calibration(int width, int height)
: width_(width)
, height_(height)
, cx_(0)
, cy_(0)
, k1_(0)
, k2_(0)
{
: width_(width), height_(height), cx_(0), cy_(0), k1_(0), k2_(0) {
// 50mm guess

double diag_35mm = 36.0 * 36.0 + 24.0 * 24.0;
double diag_pix = (double) width * (double) width + (double) height * (double) height;
double diag_pix = (double)width * (double)width + (double)height * (double)height;

f_ = 50.0 * std::sqrt(diag_pix / diag_35mm);
}
Expand All @@ -30,13 +23,15 @@ int phg::Calibration::height() const {
return height_;
}

cv::Vec3d phg::Calibration::project(const cv::Vec3d &point) const
{
cv::Vec3d phg::Calibration::project(const cv::Vec3d &point) const {
double x = point[0] / point[2];
double y = point[1] / point[2];

// TODO 11: добавьте учет радиальных искажений (k1_, k2_) (после деления на Z, но до умножения на f)

double r = x * x + y * y;
x *= 1 + k1_ * r + k2_ * r * r;
y *= 1 + k2_ * r * k2_ * r * r;

x *= f_;
y *= f_;
Expand All @@ -47,8 +42,7 @@ cv::Vec3d phg::Calibration::project(const cv::Vec3d &point) const
return cv::Vec3d(x, y, 1.0);
}

cv::Vec3d phg::Calibration::unproject(const cv::Vec2d &pixel) const
{
cv::Vec3d phg::Calibration::unproject(const cv::Vec2d &pixel) const {
double x = pixel[0] - cx_ - width_ * 0.5;
double y = pixel[1] - cy_ - height_ * 0.5;

Expand All @@ -57,5 +51,9 @@ cv::Vec3d phg::Calibration::unproject(const cv::Vec2d &pixel) const

// TODO 12: добавьте учет радиальных искажений, когда реализуете - подумайте: почему строго говоря это - не симметричная формула формуле из project? (но лишь приближение)

double r = x * x + y * y;
x /= 1 + k1_ * r + k2_ * r * r;
y /= 1 + k2_ * r * k2_ * r * r;

return cv::Vec3d(x, y, 1.0);
}
Loading
Loading