SMACC2
Loading...
Searching...
No Matches
cl_rgb::PinholeCamera Struct Reference

#include <geometry.hpp>

Collaboration diagram for cl_rgb::PinholeCamera:
Collaboration graph

Public Member Functions

cv::Vec3d rayDirection (double u, double v) const
 
std::optional< cv::Point2d > project (const cv::Vec3d &point) const
 
std::optional< cv::Vec3d > pixelToPlane (double u, double v, double z) const
 
cv::Matx33d imageToPlaneHomography (double z) const
 

Public Attributes

double fx = 1.0
 
double fy = 1.0
 
double cx = 0.0
 
double cy = 0.0
 
cv::Matx33d rotation = cv::Matx33d::eye()
 
cv::Vec3d position {0.0, 0.0, 0.0}
 

Detailed Description

Definition at line 26 of file geometry.hpp.

Member Function Documentation

◆ imageToPlaneHomography()

cv::Matx33d cl_rgb::PinholeCamera::imageToPlaneHomography ( double z) const

Definition at line 50 of file geometry.cpp.

51{
52 // With m = R K^-1 (u, v, 1), the plane point is x = ox + (z - oz) m1 / m3 and the same for y.
53 const cv::Matx33d inverseK(1.0 / fx, 0.0, -cx / fx, 0.0, 1.0 / fy, -cy / fy, 0.0, 0.0, 1.0);
54 const double h = z - position[2];
55 const cv::Matx33d toPlane(h, 0.0, position[0], 0.0, h, position[1], 0.0, 0.0, 1.0);
56 return toPlane * rotation * inverseK;
57}
cv::Matx33d rotation
Definition geometry.hpp:32

References cx, cy, fx, fy, position, and rotation.

Referenced by cl_rgb::findBlobs(), and cl_rgb::tableRegionMask().

Here is the caller graph for this function:

◆ pixelToPlane()

std::optional< cv::Vec3d > cl_rgb::PinholeCamera::pixelToPlane ( double u,
double v,
double z ) const

Definition at line 35 of file geometry.cpp.

36{
37 const cv::Vec3d d = rayDirection(u, v);
38 if (std::abs(d[2]) < 1e-12)
39 {
40 return std::nullopt;
41 }
42 const double s = (z - position[2]) / d[2];
43 if (s <= 0.0)
44 {
45 return std::nullopt;
46 }
47 return position + s * d;
48}
cv::Vec3d rayDirection(double u, double v) const
Definition geometry.cpp:20

References position, and rayDirection().

Referenced by cl_rgb::findBlobs(), cl_rgb::fitBoxOnTable(), and cl_rgb::CpTablePlane::pointUnderPixel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ project()

std::optional< cv::Point2d > cl_rgb::PinholeCamera::project ( const cv::Vec3d & point) const

Definition at line 25 of file geometry.cpp.

26{
27 const cv::Vec3d p = rotation.t() * (point - position);
28 if (p[2] <= 1e-9)
29 {
30 return std::nullopt;
31 }
32 return cv::Point2d(fx * p[0] / p[2] + cx, fy * p[1] / p[2] + cy);
33}

References cx, cy, fx, fy, position, and rotation.

Referenced by cl_rgb::anonymous_namespace{box_fit.cpp}::hullArea(), and cl_rgb::anonymous_namespace{box_fit.cpp}::outline().

Here is the caller graph for this function:

◆ rayDirection()

cv::Vec3d cl_rgb::PinholeCamera::rayDirection ( double u,
double v ) const

Definition at line 20 of file geometry.cpp.

21{
22 return rotation * cv::Vec3d((u - cx) / fx, (v - cy) / fy, 1.0);
23}

References cx, cy, fx, fy, and rotation.

Referenced by pixelToPlane().

Here is the caller graph for this function:

Member Data Documentation

◆ cx

double cl_rgb::PinholeCamera::cx = 0.0

◆ cy

double cl_rgb::PinholeCamera::cy = 0.0

◆ fx

double cl_rgb::PinholeCamera::fx = 1.0

◆ fy

double cl_rgb::PinholeCamera::fy = 1.0

◆ position

cv::Vec3d cl_rgb::PinholeCamera::position {0.0, 0.0, 0.0}

Definition at line 33 of file geometry.hpp.

33{0.0, 0.0, 0.0}; // of the optical centre, world frame

Referenced by cl_rgb::findBlobs(), imageToPlaneHomography(), cl_rgb::CpCamera::model(), pixelToPlane(), project(), and cl_rgb::tableRegionMask().

◆ rotation

cv::Matx33d cl_rgb::PinholeCamera::rotation = cv::Matx33d::eye()

The documentation for this struct was generated from the following files: