8000 Inline point to image projection by ahojnnes · Pull Request #2050 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inline point to image projection #2050

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

Merged
merged 1 commit into from
Jul 22, 2023
Merged
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
5 changes: 2 additions & 3 deletions src/colmap/base/synthetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void SynthesizeDataset(const SyntheticDatasetOptions& options,
image.CamFromWorld().rotation * -proj_center;

const Camera& camera = reconstruction->Camera(image.CameraId());
const Eigen::Matrix3x4d cam_from_world = image.CamFromWorld().ToMatrix();

std::vector<Point2D> points2D;
points2D.reserve(options.num_points3D +
Expand All @@ -96,8 +95,8 @@ void SynthesizeDataset(const SyntheticDatasetOptions& options,
// Create 3D point observations by project all 3D points to the image.
for (auto& point3D : reconstruction->Points3D()) {
Point2D point2D;
point2D.SetXY(
ProjectPointToImage(point3D.second.XYZ(), cam_from_world, camera));
point2D.SetXY(camera.ImgFromCam(
(image.CamFromWorld() * point3D.second.XYZ()).hnormalized()));
if (options.point2D_stddev > 0) {
const Eigen::Vector2d noise(
RandomGaussian<double>(0, options.point2D_stddev),
Expand Down
12 changes: 2 additions & 10 deletions src/colmap/geometry/projection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ bool DecomposeProjectionMatrix(const Eigen::Matrix3x4d& P,
return true;
}

Eigen::Vector2d ProjectPointToImage(const Eigen::Vector3d& point3D,
const Eigen::Matrix3x4d& cam_from_world,
const Camera& camera) {
return camera.ImgFromCam(
(cam_from_world * point3D.homogeneous()).hnormalized());
}

double CalculateSquaredReprojectionError(const Eigen::Vector2d& point2D,
const Eigen::Vector3d& point3D,
const Rigid3d& cam_from_world,
Expand All @@ -98,9 +91,8 @@ double CalculateSquaredReprojectionError(const Eigen::Vector2d& point2D,
return std::numeric_limits<double>::max();
}

const Eigen::Vector2d proj_point2D =
camera.ImgFromCam(point3D_in_cam.hnormalized());
return (proj_point2D - point2D).squaredNorm();
return (camera.ImgFromCam(point3D_in_cam.hnormalized()) - point2D)
.squaredNorm();
}

double CalculateSquaredReprojectionError(
Expand Down
11 changes: 0 additions & 11 deletions src/colmap/geometry/projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ bool DecomposeProjectionMatrix(const Eigen::Matrix3x4d& proj_matrix,
Eigen::Matrix3d* R,
Eigen::Vector3d* T);

// Project 3D point to image.
//
// @param points3D 3D world point as 3x1 vector.
// @param cam_from_world 3x4 projection matrix.
// @param camera Camera used to project to image plane.
//
// @return Projected image point.
Eigen::Vector2d ProjectPointToImage(const Eigen::Vector3d& point3D,
const Eigen::Matrix3x4d& cam_from_world,
const Camera& camera);

// Calculate the reprojection error.
//
// The reprojection error is the Euclidean distance between the observation
Expand Down
4 changes: 2 additions & 2 deletions src/colmap/optim/bundle_adjustment_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ void GenerateReconstruction(const size_t num_images,
EXPECT_TRUE(
HasPointPositiveDepth(cam_from_world_matrix, point3D.second.XYZ()));
// Get exact projection of 3D point.
Eigen::Vector2d point2D = ProjectPointToImage(
point3D.second.XYZ(), cam_from_world_matrix, camera);
Eigen::Vector2d point2D = camera.ImgFromCam(
(image.CamFromWorld() * point3D.second.XYZ()).hnormalized());
// Add some uniform noise.
point2D += Eigen::Vector2d(RandomUniformReal(-2.0, 2.0),
RandomUniformReal(-2.0, 2.0));
Expand Down
4 changes: 2 additions & 2 deletions src/colmap/ui/point_viewer_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ void PointViewerWidget::Show(const point3D_t point3D_id) {
const Image& image = model_viewer_widget_->images[track_el.first.image_id];
const Camera& camera = model_viewer_widget_->cameras[image.CameraId()];
const Point2D& point2D = image.Point2D(track_el.first.point2D_idx);
const Eigen::Vector2d proj_point2D = ProjectPointToImage(
point3D.XYZ(), image.CamFromWorld().ToMatrix(), camera);
const Eigen::Vector2d proj_point2D =
camera.ImgFromCam((image.CamFromWorld() * point3D.XYZ()).hnormalized());
const double reproj_error = (point2D.XY() - proj_point2D).norm();

Bitmap bitmap;
Expand Down
0