 |
AliceVision
Photogrammetric Computer Vision Framework
|
10 #include <aliceVision/types.hpp>
11 #include <aliceVision/numeric/numeric.hpp>
12 #include <aliceVision/camera/cameraCommon.hpp>
13 #include <aliceVision/camera/IntrinsicInitMode.hpp>
14 #include <aliceVision/geometry/Pose3.hpp>
15 #include <aliceVision/version.hpp>
30 using sptr = std::shared_ptr<IntrinsicBase>;
52 inline unsigned int w()
const {
return _w; }
58 inline unsigned int h()
const {
return _h; }
76 inline const std::string&
serialNumber()
const {
return _serialNumber; }
91 inline bool operator!=(
const IntrinsicBase& other)
const {
return !(*
this == other); }
112 virtual Vec2
transformProject(
const Eigen::Matrix4d& pose,
const Vec4& pt3D,
bool applyDistortion =
true)
const = 0;
120 virtual Vec2
project(
const Vec4& pt3D,
bool applyDistortion =
true)
const = 0;
131 bool applyUndistortion =
true,
133 double depth = 1.0)
const;
142 Vec4 getCartesianfromSphericalCoordinates(
const Vec3& pt);
144 Eigen::Matrix<double, 4, 3> getDerivativeCartesianfromSphericalCoordinates(
const Vec3& pt);
194 assert(X.cols() == x.cols());
195 const std::size_t numPts = x.cols();
196 Mat2X
residuals = Mat2X::Zero(2, numPts);
197 for (std::size_t i = 0; i < numPts; ++i)
199 residuals.col(i) =
residual(pose, ((
const Vec3&)X.col(i)).homogeneous(), x.col(i));
218 inline void setWidth(
unsigned int width) { _w = width; }
224 inline void setHeight(
unsigned int height) { _h = height; }
267 virtual EINTRINSIC
getType()
const = 0;
307 virtual Vec2
cam2ima(
const Vec2& p)
const = 0;
314 virtual Vec2
ima2cam(
const Vec2& p)
const = 0;
379 virtual bool isValid()
const {
return _w != 0 && _h != 0; }
393 virtual bool isVisible(
const Vec2& pix)
const;
400 virtual bool isVisible(
const Vec2f& pix)
const;
422 virtual void rescale(
float factorW,
float factorH);
453 _state = EEstimatorParameterState::CONSTANT;
457 _state = EEstimatorParameterState::REFINED;
474 std::string _serialNumber;
475 double _sensorWidth = 36.0;
476 double _sensorHeight = 24.0;
511 inline double angleBetweenRays(
const Vec3& ray1,
const Vec3& ray2)
513 const double mag = ray1.norm() * ray2.norm();
514 const double dotAngle = ray1.dot(ray2);
515 return radianToDegree(acos(
clamp(dotAngle / mag, -1.0 + 1.e-8, 1.0 - 1.e-8)));
528 inline double angleBetweenRays(
const geometry::Pose3& pose1,
529 const IntrinsicBase* intrinsic1,
530 const geometry::Pose3& pose2,
531 const IntrinsicBase* intrinsic2,
535 const Vec3 ray1 = applyIntrinsicExtrinsic(pose1, intrinsic1, x1);
536 const Vec3 ray2 = applyIntrinsicExtrinsic(pose2, intrinsic2, x2);
537 return angleBetweenRays(ray1, ray2);
547 inline double angleBetweenRays(
const geometry::Pose3& pose1,
const geometry::Pose3& pose2,
const Vec3& pt3D)
549 const Vec3 ray1 = pt3D - pose1.center();
550 const Vec3 ray2 = pt3D - pose2.center();
551 return angleBetweenRays(ray1, ray2);
virtual double getHorizontalFov() const =0
Get the horizontal FOV in radians.
void setWidth(unsigned int width)
Set the intrinsic image width.
Definition: IntrinsicBase.hpp:218
EEstimatorParameterState
Defines the state of a parameter for an estimator.
Definition: types.hpp:38
double sensorWidth() const
Get the intrinsic sensor width.
Definition: IntrinsicBase.hpp:64
bool _locked
intrinsic lock
Definition: IntrinsicBase.hpp:484
virtual double getVerticalFov() const =0
Get the vertical FOV in radians.
virtual void setDistortionInitializationMode(EInitMode distortionInitializationMode)=0
Set The intrinsic disto initialization mode.
EInitMode getInitializationMode() const
Get the intrinsic initialization mode.
Definition: IntrinsicBase.hpp:82
Vec2 transformProject(const geometry::Pose3 &pose, const Vec4 &pt3D, bool applyDistortion=true) const
Projection of a 3D point into the camera plane (Apply pose, disto (if any) and Intrinsics)
Definition: IntrinsicBase.hpp:100
virtual void assign(const IntrinsicBase &other)=0
Assign object.
virtual std::size_t hashValue() const
Generate an unique Hash from the camera parameters (used for grouping)
Definition: IntrinsicBase.cpp:87
virtual std::size_t getParametersSize() const =0
Get the count of intrinsic parameters.
double sensorHeight() const
Get the intrinsic sensor height.
Definition: IntrinsicBase.hpp:70
virtual void initializeState()
Initialize state with default values The estimator state is used in the bundle adjustment to decide i...
Definition: IntrinsicBase.hpp:449
EEstimatorParameterState getState() const
accessor to estimator state
Definition: IntrinsicBase.hpp:465
virtual bool importFromParams(const std::vector< double > ¶ms, const Version &inputVersion)=0
Import intrinsic parameters from external array.
virtual Vec2 cam2ima(const Vec2 &p) const =0
Transform a point from the camera plane to the image plane.
unsigned int h() const
Get the intrinsic image height.
Definition: IntrinsicBase.hpp:58
void lock()
Lock the intrinsic.
Definition: IntrinsicBase.hpp:207
Vec3 backprojectTransform(const Vec2 &pt2D, bool applyUndistortion=true, const geometry::Pose3 &pose=geometry::Pose3(), double depth=1.0) const
Back-projection of a 2D point at a specific depth into a 3D point.
Definition: IntrinsicBase.cpp:20
virtual float getMaximalDistortion(double minRadius, double maxRadius) const
Assuming the distortion is a function of radius, estimate the maximal undistorted radius for a range ...
Definition: IntrinsicBase.cpp:81
virtual bool isValid() const
Return true if the intrinsic is valid.
Definition: IntrinsicBase.hpp:379
virtual bool operator==(const IntrinsicBase &other) const
operator ==
Definition: IntrinsicBase.cpp:14
Definition: checkerDetector.cpp:32
virtual Vec3 toUnitSphere(const Vec2 &pt) const =0
Transform a given point (in pixels) to unit sphere in meters.
virtual bool updateFromParams(const std::vector< double > ¶ms)=0
Update intrinsic parameters.
unsigned int w() const
Get the intrinsic image width.
Definition: IntrinsicBase.hpp:52
const std::string & serialNumber() const
Get the intrinsic serial number.
Definition: IntrinsicBase.hpp:76
virtual Eigen::Matrix< double, 2, 3 > getDerivativeTransformProjectWrtPoint3(const Eigen::Matrix4d &pose, const Vec4 &pt3D) const =0
Get the derivative of a projection of a 3D point into the camera plane.
Mat2X residuals(const geometry::Pose3 &pose, const Mat3X &X, const Mat2X &x) const
Compute the residuals between the 3D projected point X and an image observation x.
Definition: IntrinsicBase.hpp:192
virtual bool isVisible(const Vec2 &pix) const
Return true if these pixel coordinates should be visible in the image.
Definition: IntrinsicBase.cpp:61
virtual std::vector< double > getParameters() const =0
Get the intrinsic parameters.
bool isLocked() const
Get the lock state of the intrinsic.
Definition: IntrinsicBase.hpp:46
virtual Vec2 addDistortion(const Vec2 &p) const =0
Add the distortion field to a point (that is in normalized camera frame)
virtual EInitMode getDistortionInitializationMode() const =0
Get the intrinsic disto initialization mode.
void setSensorHeight(double height)
Set the intrinsic sensor height.
Definition: IntrinsicBase.hpp:236
Definition: version.hpp:30
virtual IntrinsicBase * clone() const =0
Polymorphic clone.
void setState(EEstimatorParameterState state)
mutator for the estimator state
Definition: IntrinsicBase.hpp:471
void setSerialNumber(const std::string &serialNumber)
Set the serial number.
Definition: IntrinsicBase.hpp:242
void unlock()
Unlock the intrinsic.
Definition: IntrinsicBase.hpp:212
Vec3 backProjectUnit(const Vec2 &pt2D) const
Back-projection of a 2D point on a unitsphere.
Definition: IntrinsicBase.cpp:30
virtual Eigen::Matrix< double, 3, Eigen::Dynamic > getDerivativeBackProjectUnitWrtParams(const Vec2 &pt2D) const =0
Get the derivative of the unit sphere backprojection.
T clamp(const T &val, const T &min, const T &max)
Clamp return the number if inside range, else min or max range.
Definition: numeric.hpp:140
virtual Vec2 getUndistortedPixel(const Vec2 &p) const =0
Return the undistorted pixel (with removed distortion)
void setSensorWidth(double width)
Set the intrinsic sensor width.
Definition: IntrinsicBase.hpp:230
virtual double imagePlaneToCameraPlaneError(double value) const =0
Normalize a given unit pixel error to the camera plane.
virtual bool isVisibleRay(const Vec3 &ray) const =0
Return true if this ray should be visible in the image.
Basis class for all intrinsic parameters of a camera.
Definition: IntrinsicBase.hpp:27
virtual Vec2 project(const Vec4 &pt3D, bool applyDistortion=true) const =0
Projection of a 3D point into the camera plane (Apply disto (if any) and Intrinsics)
virtual EINTRINSIC getType() const =0
Get embed camera type.
virtual double pixelProbability() const =0
What is the probability of a pixel wrt the whole fov.
virtual void rescale(float factorW, float factorH)
Rescale intrinsics to reflect a rescale of the camera image.
Definition: IntrinsicBase.cpp:106
virtual Vec2 getDistortedPixel(const Vec2 &p) const =0
Return the distorted pixel (with added distortion)
std::string getTypeStr() const
Get the string describing the intrinsic type.
Definition: IntrinsicBase.hpp:273
Vec2 residual(const geometry::Pose3 &pose, const Vec4 &X, const Vec2 &x, bool applyDistortion=true) const
Compute the residual between the 3D projected point X and an image observation x.
Definition: IntrinsicBase.hpp:177
virtual Vec2 ima2cam(const Vec2 &p) const =0
Transform a point from the image plane to the camera plane.
void setInitializationMode(EInitMode initializationMode)
Set the intrinsic initialization mode.
Definition: IntrinsicBase.hpp:248
virtual bool hasDistortion() const
Camera model handles a distortion field.
Definition: IntrinsicBase.hpp:320
void setHeight(unsigned int height)
Set the intrinsic image height.
Definition: IntrinsicBase.hpp:224
virtual Eigen::Matrix< double, 2, Eigen::Dynamic > getDerivativeTransformProjectWrtParams(const Eigen::Matrix4d &pos, const Vec4 &pt3D) const =0
Get the derivative of a projection of a 3D point into the camera plane.
virtual Vec2 removeDistortion(const Vec2 &p) const =0
Remove the distortion to a camera point (that is in normalized camera frame)
EInitMode _initializationMode
initialization mode
Definition: IntrinsicBase.hpp:481