ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
EquirectProjection.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4//
5// Equirectangular (360 panorama) <-> perspective (pinhole) reprojection.
6//
7// The codebase has no spherical-image geometry outside the VTK viewer, which
8// only *samples* an equirect texture onto a sphere for display
9// (apps/rux/src/view/panorama_handler.cpp). This utility provides the CPU
10// geometry shared by two features:
11// * SAM3-on-360 : slice an equirect into pinhole tiles the segmenter can
12// consume at its native resolution, then stitch the per-tile
13// label maps back into one equirect label image.
14// * 360 alignment: render a virtual pinhole view of the panorama toward a
15// nearby sensor frame so it can be ORB-matched, and map
16// slice pixels back to panorama bearings for pose resection.
17//
18// Panorama frame convention (right-handed, camera-style y-down):
19// longitude theta in [-pi, pi] -> column u in [0, W)
20// latitude phi in [-pi/2,pi/2] -> row v in [0, H) (v=0 = north pole)
21// bearing d(theta,phi) = ( sin(theta) cos(phi),
22// -sin(phi),
23// cos(theta) cos(phi) )
24// so d(0,0) = +Z (forward), +X points right (theta>0), +Y points down. This is
25// the same optical convention (x right, y down, z forward) the rest of the
26// pipeline uses for sensor-frame cameras, so a resected panorama pose composes
27// directly with sensor-frame poses.
28
29#pragma once
30
31#include <Eigen/Core>
32#include <opencv2/core.hpp>
33
34#include <vector>
35
36namespace reusex::geometry {
37
40 cv::Mat image;
41 Eigen::Matrix3d K;
42 Eigen::Matrix3d
44 double fov_deg = 90.0;
45 double yaw_deg = 0.0;
46 double pitch_deg = 0.0;
47};
48
50Eigen::Vector3d pixel_to_bearing(const cv::Size &equirect, double u, double v);
51
54Eigen::Vector2d bearing_to_pixel(const cv::Size &equirect,
55 const Eigen::Vector3d &bearing);
56
60PerspectiveView extract_perspective(const cv::Mat &equirect, double yaw_deg,
61 double pitch_deg, double fov_deg, int out_w,
62 int out_h, int interp = 1 /*INTER_LINEAR*/);
63
67PerspectiveView extract_perspective(const cv::Mat &equirect,
68 const Eigen::Matrix3d &R_pano_from_view,
69 const Eigen::Matrix3d &K, int out_w,
70 int out_h, int interp = 1);
71
74std::vector<PerspectiveView> cube_faces(const cv::Mat &equirect, int face_size,
75 int interp = 1);
76
82std::vector<PerspectiveView> overlapping_views(const cv::Mat &equirect,
83 int n_yaw, double fov_deg,
84 int tile, int interp = 1);
85
91cv::Mat stitch_labels_to_equirect(const cv::Size &out,
92 const std::vector<PerspectiveView> &views,
93 const std::vector<cv::Mat> &tile_labels);
94
95} // namespace reusex::geometry
Eigen::Vector2d bearing_to_pixel(const cv::Size &equirect, const Eigen::Vector3d &bearing)
Unit bearing (need not be normalised) in panorama frame -> equirect pixel (u,v).
Eigen::Vector3d pixel_to_bearing(const cv::Size &equirect, double u, double v)
Equirect pixel (u,v) -> unit bearing in the panorama frame.
std::vector< PerspectiveView > overlapping_views(const cv::Mat &equirect, int n_yaw, double fov_deg, int tile, int interp=1)
Tile the sphere as n_yaw evenly spaced views around the equator plus one up and one down view,...
PerspectiveView extract_perspective(const cv::Mat &equirect, double yaw_deg, double pitch_deg, double fov_deg, int out_w, int out_h, int interp=1)
Render a virtual pinhole view centred at (yaw,pitch) with the given horizontal FOV.
cv::Mat stitch_labels_to_equirect(const cv::Size &out, const std::vector< PerspectiveView > &views, const std::vector< cv::Mat > &tile_labels)
Stitch per-tile label maps (CV_32S, -1 = background) back into a single equirect label map of size ou...
std::vector< PerspectiveView > cube_faces(const cv::Mat &equirect, int face_size, int interp=1)
Tile the whole sphere as the six faces of a cube (90 deg FOV each).
A virtual pinhole view rendered out of an equirectangular panorama.
cv::Mat image
rendered pinhole image (same type as source)
double fov_deg
horizontal field of view used to build K
Eigen::Matrix3d K
intrinsics of the virtual pinhole camera
Eigen::Matrix3d R_pano_from_view
maps view-camera rays into panorama frame
double pitch_deg
view centre latitude (deg)
double yaw_deg
view centre longitude (deg)