Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #6291 and #6236 #6305

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cpp/open3d/geometry/PointCloudSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@ class RANSACResult {
};

// Calculates the number of inliers given a list of points and a plane model,
// and the total distance between the inliers and the plane. These numbers are
// then used to evaluate how well the plane model fits the given points.
// and the total squared point-to-plane distance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the total squared point-to-plane distance be root mean squared point-to-plane distance? Not a major issue though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, 1 minute late :D .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know and I can push this change when making other documentation PRs. This anyways is not getting rendered to C++ docs, so probably needs more work to make it doxygen compatible - http://www.open3d.org/docs/release/cpp_api/namespaceopen3d_1_1geometry.html#a5013df32089b6fb7222d04535759b7d4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: The comments in .cpp files are for code authors (how does it work?) and comments in header files (Doxygen compatible) are for API users (what does it do, inputs and output).

// These numbers are then used to evaluate how well the plane model fits the
// given points.
RANSACResult EvaluateRANSACBasedOnDistance(
const std::vector<Eigen::Vector3d> &points,
const Eigen::Vector4d plane_model,
std::vector<size_t> &inliers,
double distance_threshold,
double error) {
double distance_threshold) {
RANSACResult result;

double error = 0;
for (size_t idx = 0; idx < points.size(); ++idx) {
Eigen::Vector4d point(points[idx](0), points[idx](1), points[idx](2),
1);
double distance = std::abs(plane_model.dot(point));

if (distance < distance_threshold) {
error += distance;
theNded marked this conversation as resolved.
Show resolved Hide resolved
error += distance * distance;
inliers.emplace_back(idx);
}
}
Expand All @@ -91,7 +92,7 @@ RANSACResult EvaluateRANSACBasedOnDistance(
result.inlier_rmse_ = 0;
} else {
result.fitness_ = (double)inlier_num / (double)points.size();
result.inlier_rmse_ = error / std::sqrt((double)inlier_num);
result.inlier_rmse_ = std::sqrt(error / (double)inlier_num);
ssheorey marked this conversation as resolved.
Show resolved Hide resolved
}
return result;
}
Expand Down Expand Up @@ -202,10 +203,9 @@ std::tuple<Eigen::Vector4d, std::vector<size_t>> PointCloud::SegmentPlane(
continue;
}

double error = 0;
inliers.clear();
auto this_result = EvaluateRANSACBasedOnDistance(
points_, plane_model, inliers, distance_threshold, error);
points_, plane_model, inliers, distance_threshold);
#pragma omp critical
{
if (this_result.fitness_ > result.fitness_ ||
Expand Down
12 changes: 9 additions & 3 deletions cpp/open3d/geometry/RGBDImageFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ std::shared_ptr<RGBDImage> RGBDImage::CreateFromColorAndDepth(
bool convert_rgb_to_intensity /* = true*/) {
std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
if (color.height_ != depth.height_ || color.width_ != depth.width_) {
utility::LogError("Unsupported image format.");
utility::LogError(
"RGB image size ({} {}) and depth image size ({} {}) mismatch.",
color.height_, color.width_, depth.height_, depth.width_);
theNded marked this conversation as resolved.
Show resolved Hide resolved
}
rgbd_image->depth_ =
*depth.ConvertDepthToFloatImage(depth_scale, depth_trunc);
Expand Down Expand Up @@ -55,7 +57,9 @@ std::shared_ptr<RGBDImage> RGBDImage::CreateFromSUNFormat(
bool convert_rgb_to_intensity /* = true*/) {
std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
if (color.height_ != depth.height_ || color.width_ != depth.width_) {
utility::LogError("Unsupported image format.");
utility::LogError(
"RGB image size ({} {}) and depth image size ({} {}) mismatch.",
color.height_, color.width_, depth.height_, depth.width_);
}
for (int v = 0; v < depth.height_; v++) {
for (int u = 0; u < depth.width_; u++) {
Expand All @@ -75,7 +79,9 @@ std::shared_ptr<RGBDImage> RGBDImage::CreateFromNYUFormat(
bool convert_rgb_to_intensity /* = true*/) {
std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
if (color.height_ != depth.height_ || color.width_ != depth.width_) {
utility::LogError("Unsupported image format.");
utility::LogError(
"RGB image size ({} {}) and depth image size ({} {}) mismatch.",
color.height_, color.width_, depth.height_, depth.width_);
}
for (int v = 0; v < depth.height_; v++) {
for (int u = 0; u < depth.width_; u++) {
Expand Down