17 namespace depth_quality
38 val(val), name(name) {}
45 const std::vector<rs2::float3>&
points,
48 const float baseline_mm,
49 const float focal_length_pixels,
50 const int ground_thruth_mm,
52 const float plane_fit_to_ground_truth_mm,
53 const float distance_mm,
55 std::vector<single_metric_data>&
samples)>;
59 return{ normal.
x, normal.
y, normal.
z, -(normal.
x*point.
x + normal.
y*point.
y + normal.
z*point.
z) };
65 if (points.size() < 3)
throw std::runtime_error(
"Not enough points to calculate plane");
72 double xx = 0, xy = 0, xz = 0,
yy = 0, yz = 0, zz = 0;
73 for (
auto point : points) {
75 xx += temp.
x * temp.
x;
76 xy += temp.
x * temp.
y;
77 xz += temp.
x * temp.
z;
78 yy += temp.
y * temp.
y;
79 yz += temp.
y * temp.
z;
80 zz += temp.
z * temp.
z;
83 double det_x =
yy*zz - yz*yz;
84 double det_y = xx*zz - xz*xz;
85 double det_z = xx*
yy - xy*xy;
87 double det_max = std::max({ det_x, det_y, det_z });
88 if (det_max <= 0)
return{ 0, 0, 0, 0 };
93 float a =
static_cast<float>((xz*yz - xy*zz) / det_x);
94 float b =
static_cast<float>((xy*yz - xz*
yy) / det_x);
97 else if (det_max == det_y)
99 float a =
static_cast<float>((yz*xz - xy*zz) / det_y);
100 float b =
static_cast<float>((xy*xz - yz*
xx) / det_y);
105 float a =
static_cast<float>((yz*xy - xz*
yy) / det_z);
106 float b =
static_cast<float>((xz*xy - yz*
xx) / det_z);
115 float pixel[2] = {
x, y };
124 if (fabs(max - min) < 1
e-3)
return point;
126 if (
f*
n > 0)
return{ 0, 0, 0 };
128 auto avg = (max +
min) / 2;
141 float units,
float baseline_mm,
144 const int ground_truth_mm,
145 bool plane_fit_present,
146 std::vector<single_metric_data>&
samples,
158 std::vector<rs2::float3> roi_pixels;
169 float pixel[2] = { float(
x), float(
y) };
175 std::lock_guard<std::mutex>
lock(m);
176 roi_pixels.push_back({ point[0], point[1], point[2] });
180 if (roi_pixels.size() < 3) {
186 if (p ==
plane{ 0, 0, 0, 0 }) {
193 float plane_fit_to_gt_offset_mm = (ground_truth_mm > 0.f) ? (plane_fit_pivot.
z * 1000 - ground_truth_mm) : 0;
203 result.distance =
static_cast<float>(-p.
d * 1000);
205 result.angle =
static_cast<float>(std::acos(std::abs(p.
c)) / M_PI * 180.);
207 callback(roi_pixels, p, roi, baseline_mm, intrin->
fx, ground_truth_mm, plane_fit_present,
208 plane_fit_to_gt_offset_mm,
result.distance, record, samples);
212 auto cam =
float3{ 0.f, 0.f, -1.f };
214 auto u = cam -
n *
dot;
static const textual_icon lock
GLboolean GLboolean GLboolean b
snapshot_metrics analyze_depth_image(const rs2::video_frame &frame, float units, float baseline_mm, const rs2_intrinsics *intrin, rs2::region_of_interest roi, const int ground_truth_mm, bool plane_fit_present, std::vector< single_metric_data > &samples, bool record, callback_type callback)
plane plane_from_points(const std::vector< rs2::float3 > points)
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
GLuint const GLchar * name
double evaluate_pixel(const plane &p, const rs2_intrinsics *intrin, float x, float y, float distance, float3 &output)
float3 approximate_intersection(const plane &p, const rs2_intrinsics *intrin, float x, float y, float min, float max)
const void * get_data() const
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
std::array< float3, 4 > plane_corners
GLfloat GLfloat GLfloat GLfloat h
rs2::region_of_interest roi
float evaluate_plane(const plane &plane, const float3 &point)
GLsizei GLsizei GLfloat distance
GLboolean GLboolean GLboolean GLboolean a
static void rs2_deproject_pixel_to_point(float point[3], const struct rs2_intrinsics *intrin, const float pixel[2], float depth)
float dot(const rs2::float2 &a, const rs2::float2 &b)
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
std::function< void(const std::vector< rs2::float3 > &points, const plane p, const rs2::region_of_interest roi, const float baseline_mm, const float focal_length_pixels, const int ground_thruth_mm, const bool plane_fit, const float plane_fit_to_ground_truth_mm, const float distance_mm, bool record, std::vector< single_metric_data > &samples)> callback_type
plane plane_from_point_and_normal(const rs2::float3 &point, const rs2::float3 &normal)
single_metric_data(std::string name, float val)