Skip to content

Commit

Permalink
Merge pull request #436 from nitrotm/ba-intrinsics3
Browse files Browse the repository at this point in the history
Use principal point in feature normalization and radial distortion in BA
  • Loading branch information
simonfuhrmann authored May 31, 2018
2 parents 5cd9c02 + 74b1d7a commit 2106a5b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
3 changes: 3 additions & 0 deletions libs/sfm/bundler_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct Viewport
float focal_length;
/** Radial distortion parameter. */
float radial_distortion[2];
/** Principal point parameter. */
float principal_point[2];

/** Camera pose for the viewport. */
CameraPose pose;
Expand Down Expand Up @@ -201,6 +203,7 @@ Viewport::Viewport (void)
: focal_length(0.0f)
{
std::fill(this->radial_distortion, this->radial_distortion + 2, 0.0f);
std::fill(this->principal_point, this->principal_point + 2, 0.5f);
}

inline bool
Expand Down
3 changes: 2 additions & 1 deletion libs/sfm/bundler_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Features::compute (mve::Scene::Ptr scene, ViewportList* viewports)
Viewport* viewport = &viewports->at(i);
viewport->features.set_options(this->opts.feature_options);
viewport->features.compute_features(image);
viewport->features.normalize_feature_positions();
viewport->features.normalize_feature_positions(
viewport->principal_point[0], viewport->principal_point[1]);

#pragma omp critical
{
Expand Down
19 changes: 5 additions & 14 deletions libs/sfm/bundler_intrinsics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,12 @@ Intrinsics::init_from_views (mve::View::Ptr view, Viewport* viewport)
return;
}

/*
* The current implementation sets the focal length from the view
* but uses defaults for radial distortion and principle point.
*
* TODO: Also use pre-defined radial distortion and principal point.
*
* RD: To support radial distortion, read "camera.radial_distortion"
* from the view and set it here. It must be in PBA format.
* PP: To support principle point, use CameraInfo::ppoint and set it in
* the viewport. Note that a new field is required for this, and it
* needs to be processed elsewhere.
*/
/* Sets the focal length, radial distortion and principal point from the view. */
viewport->focal_length = camera.flen;
viewport->radial_distortion[0] = 0.0f;
viewport->radial_distortion[1] = 0.0f;
viewport->radial_distortion[0] = camera.dist[0];
viewport->radial_distortion[1] = camera.dist[1];
viewport->principal_point[0] = camera.ppoint[0];
viewport->principal_point[1] = camera.ppoint[1];
}

void
Expand Down
3 changes: 3 additions & 0 deletions libs/sfm/camera_pose.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ SFM_NAMESPACE_BEGIN
* K = | 0 f py | and the principal point px and py.
* | 0 0 1 |
*
* As the feature coordinates are normalized before pose estimation, the
* principal point (px, py) is set to 0.0.
*
* For pose estimation, the calibration matrix is assumed to be known. This
* might not be the case, but even a good guess of the focal length and the
* principal point set to the image center can produce reasonably good
Expand Down
6 changes: 3 additions & 3 deletions libs/sfm/feature_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FeatureSet::compute_features (mve::ByteImage::Ptr image)
}

void
FeatureSet::normalize_feature_positions (void)
FeatureSet::normalize_feature_positions (float px, float py)
{
/* Normalize image coordinates. */
float const fwidth = static_cast<float>(this->width);
Expand All @@ -49,8 +49,8 @@ FeatureSet::normalize_feature_positions (void)
for (std::size_t i = 0; i < this->positions.size(); ++i)
{
math::Vec2f& pos = this->positions[i];
pos[0] = (pos[0] + 0.5f - fwidth / 2.0f) / fnorm;
pos[1] = (pos[1] + 0.5f - fheight / 2.0f) / fnorm;
pos[0] = (pos[0] + 0.5f - fwidth * px) / fnorm;
pos[1] = (pos[1] + 0.5f - fheight * py) / fnorm;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/sfm/feature_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FeatureSet
void compute_features (mve::ByteImage::Ptr image);

/** Normalizes the features positions w.r.t. the image dimensions. */
void normalize_feature_positions (void);
void normalize_feature_positions (float px, float py);

/** Clear descriptor data. */
void clear_descriptors (void);
Expand Down

0 comments on commit 2106a5b

Please sign in to comment.