Image and Lens API
Source headers: raptor/image.hpp, raptor/lens.hpp
raptor
Types
| Name | Description |
|---|---|
| Image | Owning image container. |
| ImageType | Image format type identifier. |
| ImageView | Non-owning view over image data. |
| LensModel | Type-erased lens model. |
Functions
| Name | Description |
|---|---|
| channels | Get number of channels for an image type. |
Function Details
channels
constexpr std::uint32_t channels(ImageType type) noexcept
Get number of channels for an image type
Parameters:
type- The image type
Returns: Number of channels (1, 3, or 4)
raptor::Image
class Image
Owning image container
Owns the image data and provides direct access to image properties.
Example:
Image image{ImageType::Rgb8, 1920, 1080, data};
std::int32_t w = image.width();
std::int32_t h = image.height();
std::uint8_t* ptr = image.bytes().data();
Functions
| Name | Description |
|---|---|
| Image | Construct an image from raw image data (copies data from span). |
| Image | Construct an image from raw image data (copies data from pointer). |
| Image | Construct an image from an ImageView (copies data). |
| type | Image format type. |
| width | Image width in pixels. |
| height | Image height in pixels. |
| channels | Number of channels per pixel. |
| numPixels | Total number of pixels (width * height). |
| bytes | Image data as a mutable span of bytes. |
| bytes | Image data as a const span of bytes. |
Function Details
Image
Image(ImageType type, std::int32_t width, std::int32_t height, std::span<const std::uint8_t> data)
Construct an image from raw image data (copies data from span)
Parameters:
type- Image format typewidth- Image width in pixelsheight- Image height in pixelsdata- Span of image data to copy Throws:std::invalid_argument- If width or height is non-positive, data is empty, or data.size() does not equal width * height * channels(type).
Image(ImageType type, std::int32_t width, std::int32_t height, const std::uint8_t* data)
Construct an image from raw image data (copies data from pointer)
Parameters:
type- Image format typewidth- Image width in pixelsheight- Image height in pixelsdata- Pointer to image data to copy Throws:std::invalid_argument- If width or height is non-positive, or data is null.
explicit Image(const ImageView& view)
Construct an image from an ImageView (copies data)
Parameters:
view- View to copy data from Throws:std::invalid_argument- If the view has non-positive dimensions or empty data.
type
[[nodiscard]] ImageType type() const noexcept
Returns: Image format type
width
[[nodiscard]] std::int32_t width() const noexcept
Returns: Image width in pixels
height
[[nodiscard]] std::int32_t height() const noexcept
Returns: Image height in pixels
channels
[[nodiscard]] std::uint32_t channels() const noexcept
Returns: Number of channels per pixel
numPixels
[[nodiscard]] std::size_t numPixels() const noexcept
Returns: Total number of pixels (width * height)
bytes
[[nodiscard]] std::span<std::uint8_t> bytes() noexcept
Returns: Image data as a mutable span of bytes
[[nodiscard]] std::span<const std::uint8_t> bytes() const noexcept
Returns: Image data as a const span of bytes
raptor::ImageType
enum class ImageType : std::uint32_t
Image format type identifier
Enumeration identifying the pixel format of an image.
Gray8 = 0 : Single channel, 8 bits per pixel
Rgb8 = 1 : 3 channels (red, green, blue), 8 bits per channel
Rgba8 = 2 : 4 channels (red, green, blue, alpha), 8 bits per channel
raptor::ImageView
class ImageView
Non-owning view over image data
Lightweight container for passing images without ownership. Provides direct access to image properties and data.
The caller must ensure the underlying data outlives the ImageView.
Example:
ImageView view{ImageType::Rgb8, 1920, 1080, data};
std::int32_t w = view.width();
std::int32_t h = view.height();
std::uint32_t ch = view.channels();
const std::uint8_t* ptr = view.bytes().data();
Functions
| Name | Description |
|---|---|
| ImageView | Construct a view from raw image data (span). |
| ImageView | Construct a view from raw image data (pointer). |
| ImageView | Construct a view from an Image. |
| type | Image format type. |
| width | Image width in pixels. |
| height | Image height in pixels. |
| channels | Number of channels per pixel. |
| numPixels | Total number of pixels (width * height). |
| bytes | Image data as a span of bytes. |
Function Details
ImageView
ImageView(ImageType type, std::int32_t width, std::int32_t height, std::span<const std::uint8_t> data) noexcept
Construct a view from raw image data (span)
Parameters:
type- Image format typewidth- Image width in pixelsheight- Image height in pixelsdata- Span of image data (must outlive this view)
ImageView(ImageType type, std::int32_t width, std::int32_t height, const std::uint8_t* data) noexcept
Construct a view from raw image data (pointer)
Parameters:
type- Image format typewidth- Image width in pixelsheight- Image height in pixelsdata- Pointer to image data (must outlive this view)
ImageView(const Image& image) noexcept
Construct a view from an Image
Parameters:
image- The image to create a view from (must outlive this view)
type
[[nodiscard]] ImageType type() const noexcept
Returns: Image format type
width
[[nodiscard]] std::int32_t width() const noexcept
Returns: Image width in pixels
height
[[nodiscard]] std::int32_t height() const noexcept
Returns: Image height in pixels
channels
[[nodiscard]] std::uint32_t channels() const noexcept
Returns: Number of channels per pixel
numPixels
[[nodiscard]] std::size_t numPixels() const noexcept
Returns: Total number of pixels (width * height)
bytes
[[nodiscard]] std::span<const std::uint8_t> bytes() const noexcept
Returns: Image data as a span of bytes
raptor::LensModel
class LensModel
Type-erased lens model
Encapsulates a projection equation choice together with its parameter values in an ABI-stable internal format. Behaves like a variant - you can only retrieve the same params type that was stored.
Example:
// Create directly from explicit pinhole parameters
LensModel l1{lens::Pinhole{
.fx = 1000.0, .fy = 1000.0, .cx = 960.0, .cy = 540.0}};
// Or from FOV using the Pinhole factory method (~90° x ~53° FOV)
LensModel l2{lens::Pinhole::fromFov(1.5708, 0.9273, 1920, 1080)};
// Get as Pinhole (same type as stored)
const auto& pinhole = l1.get<lens::Pinhole>(); // OK
// Check params type before getting
if (l1.holds<lens::Pinhole>()) {
const auto& p = l1.get<lens::Pinhole>();
}
// Use visitor pattern
l1.visit([](const auto& params) {
// Handle each params type
});
Functions
| Name | Description |
|---|---|
| LensModel | Default constructor - creates identity pinhole lens model. |
| LensModel | Create lens model from Pinhole lens parameters. |
| LensModel | Create lens model from pinhole parameters with radial distortion. |
| LensModel | Create lens model from rational radial-tangential parameters. |
| get | Get lens parameters in specified params format. |
| holds | Check if lens model holds a specific params type. |
| visit | Apply a visitor to the stored lens parameters. |
Function Details
LensModel
LensModel()
Default constructor - creates identity pinhole lens model
Creates a pinhole lens model with fx=fy=1.0, cx=cy=0.0.
explicit LensModel(const lens::Pinhole& params)
Create lens model from Pinhole lens parameters
Parameters:
params- Pinhole lens parameter struct
explicit LensModel(const lens::VantorPolynomialRadial& params)
Create lens model from pinhole parameters with radial distortion.
explicit LensModel(const lens::RationalRadialTangential& params)
Create lens model from rational radial-tangential parameters.
get
template<typename ParamsType> [[nodiscard]] const ParamsType& get() const
Get lens parameters in specified params format
ParamsType:
: lens::Pinhole, etc.
Returns: Reference to lens parameters in the specified params format
Throws: std::bad_variant_access - if ParamsType does not match the stored params type
holds
template<typename ParamsType> [[nodiscard]] bool holds() const noexcept
Check if lens model holds a specific params type
ParamsType:
: lens::Pinhole, etc.
Returns: true if the stored params matches ParamsType
visit
template<typename Visitor> decltype(auto) visit(Visitor&& vis) const
Apply a visitor to the stored lens parameters
Visitor
: Callable that accepts each supported lens params type
Parameters:
vis- Visitor callable
Returns: Result of calling visitor with the stored params
Example using raptor::Overloaded for combining lambdas:
#include "raptor/overloaded.hpp"
lens.visit(raptor::Overloaded{
[](const lens::Pinhole& p) { std::cout << "fx=" << p.fx << "\n"; },
// [](const lens::Fisheye& f) { ... }, // add handlers for future params
});
raptor::lens
Types
| Name | Description |
|---|---|
| Pinhole | Pinhole lens parameters. |
| RationalRadialTangential | Perspective pinhole lens with rational radial-tangential distortion. |
| VantorPolynomialRadial | Vantor polynomial radial lens model. |
raptor::lens::Pinhole
struct Pinhole
Pinhole lens parameters
Standard pinhole camera with focal lengths and principal point. No lens distortion.
Variables
| Name | Description |
|---|---|
| fx | Focal length in pixels (width axis); must be finite and > 0. |
| fy | Focal length in pixels (height axis); must be finite and > 0. |
| cx | Principal point x (width axis); must be finite and >= 0. |
| cy | Principal point y (height axis); must be finite and >= 0. |
Functions
| Name | Description |
|---|---|
| fromFov | Create Pinhole parameters from field of view angles. |
Variable Details
cx
double cx
Principal point x (width axis); must be finite and >= 0
cy
double cy
Principal point y (height axis); must be finite and >= 0
fx
double fx
Focal length in pixels (width axis); must be finite and > 0
fy
double fy
Focal length in pixels (height axis); must be finite and > 0
Function Details
fromFov
[[nodiscard]] static Pinhole fromFov(double hfov, double vfov, std::int32_t width, std::int32_t height)
Create Pinhole parameters from field of view angles
The principal point (cx, cy) is assumed to be at the image center. Focal lengths are computed using: f = (size/2) / tan(fov/2)
Parameters:
hfov- Horizontal field of view in radiansvfov- Vertical field of view in radianswidth- Image width in pixelsheight- Image height in pixels
Returns: Pinhole parameters with principal point at image center
Throws: std::invalid_argument - If hfov or vfov is not finite, not positive, or > π.
raptor::lens::RationalRadialTangential
struct RationalRadialTangential
Perspective pinhole lens with rational radial-tangential distortion.
For undistorted normalized coordinates and , the distorted coordinates are:
Pixels are .
This matches OpenCV's rational model.
Variables
| Name | Description |
|---|---|
| fx | Focal length in pixels (width axis); must be finite and > 0. |
| fy | Focal length in pixels (height axis); must be finite and > 0. |
| cx | Principal point x (width axis); must be finite and >= 0. |
| cy | Principal point y (height axis); must be finite and >= 0. |
| k1 | Radial coefficient; must be finite. |
| k2 | Radial coefficient; must be finite. |
| k3 | Radial coefficient; must be finite. |
| k4 | Rational-denominator coefficient; must be finite. |
| k5 | Rational-denominator coefficient; must be finite. |
| k6 | Rational-denominator coefficient; must be finite. |
| p1 | Tangential coefficient; must be finite. |
| p2 | Tangential coefficient; must be finite. |
Variable Details
cx
double cx
Principal point x (width axis); must be finite and >= 0
cy
double cy
Principal point y (height axis); must be finite and >= 0
fx
double fx
Focal length in pixels (width axis); must be finite and > 0
fy
double fy
Focal length in pixels (height axis); must be finite and > 0
k1
double k1
Radial coefficient; must be finite
k2
double k2
Radial coefficient; must be finite
k3
double k3
Radial coefficient; must be finite
k4
double k4
Rational-denominator coefficient; must be finite
k5
double k5
Rational-denominator coefficient; must be finite
k6
double k6
Rational-denominator coefficient; must be finite
p1
double p1
Tangential coefficient; must be finite
p2
double p2
Tangential coefficient; must be finite
raptor::lens::VantorPolynomialRadial
struct VantorPolynomialRadial
Vantor polynomial radial lens model.
For a camera-frame point (X, Y, Z), define undistorted normalized coordinates:
x = X / Z, y = Y / Z, r = sqrt(x*x + y*y).
The forward mapping from ideal coordinates to distorted pixels is:
c(r) = 1 + k2*r² + k3*r³ + k4*r⁴
u = fx*x*c(r) + cx
v = fy*y*c(r) + cy
This Vantor-specific model is provided for backward compatibility with calibrations from the legacy Sync product. The dimensionless coefficients k2, k3, and k4 multiply the indicated powers of the undistorted normalized radius, including the odd-power term r³. Distortion is centered at the principal point; no tangential distortion or skew is represented. Setting all three coefficients to zero gives an undistorted mapping.
Use calibration parameters matching these equations, including their radius normalization and ideal-to-distorted mapping direction. Coefficient names alone do not establish compatibility with another calibration model.
Undistortion requires solving r_distorted = r*c(r) for r. The radial mapping must be one-to-one over the radius range used by the camera.
Variables
| Name | Description |
|---|---|
| fx | Focal length in pixels (width axis); must be finite and > 0. |
| fy | Focal length in pixels (height axis); must be finite and > 0. |
| cx | Principal point x (width axis); must be finite and >= 0. |
| cy | Principal point y (height axis); must be finite and >= 0. |
| k2 | Coefficient of r²; must be finite. |
| k3 | Coefficient of r³; must be finite. |
| k4 | Coefficient of r⁴; must be finite. |
Functions
| Name | Description |
|---|---|
| fromFov | Create parameters from undistorted field-of-view angles and distortion coefficients. |
Variable Details
cx
double cx
Principal point x (width axis); must be finite and >= 0
cy
double cy
Principal point y (height axis); must be finite and >= 0
fx
double fx
Focal length in pixels (width axis); must be finite and > 0
fy
double fy
Focal length in pixels (height axis); must be finite and > 0
k2
double k2
Coefficient of r²; must be finite
k3
double k3
Coefficient of r³; must be finite
k4
double k4
Coefficient of r⁴; must be finite
Function Details
fromFov
[[nodiscard]] static VantorPolynomialRadial fromFov(double hfov, double vfov, std::int32_t width, std::int32_t height, double k2 = 0.0, double k3 = 0.0, double k4 = 0.0)
Create parameters from undistorted field-of-view angles and distortion coefficients.
Focal lengths use f = (size/2) / tan(fov/2) independently for each axis. The principal point is (width/2, height/2). Distortion coefficients are copied unchanged; they do not adjust this field-of-view relationship. With nonzero distortion, these angles do not generally equal the actual angular coverage of the distorted image.
Parameters:
hfov- Undistorted horizontal field of view in radiansvfov- Undistorted vertical field of view in radianswidth- Image width in pixelsheight- Image height in pixelsk2- Coefficient of r² in the normalized-radius scalek3- Coefficient of r³ in the normalized-radius scalek4- Coefficient of r⁴ in the normalized-radius scale
Returns: Parameters with principal point at the image center
Throws: std::invalid_argument - If hfov or vfov is not finite, not positive, or > π.