Skip to content

Add ICP support for 3d point clouds #465

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

Merged
merged 12 commits into from
Apr 2, 2021

Conversation

NobleBumblebee
Copy link
Contributor

Reference issue

fix #464

What does this implement/fix?

Adds an implementation of code for ICP to work both for 2d and 3d point clouds.

Additional information

Make functions icp_matching() and update_homogeneous_matrix() flexible. Depending on the current_points.shape[0] function svd_motion_estimation() automatically returns the correct size for Rt, Tt. Then, in update_homogeneous_matrix() depending on their size matrix H is formed to be 3x3 or 4x4.

Test for 3d point cloud is provided. Made the same manner as tests for 2d point cloud.

Shamil GEMUEV added 2 commits January 25, 2021 17:03
* icp_matching function returns R,T corresponding to 2D or 3D set of points
* update_homogeneuous_matrix - general operations for translation and rotation matrixes
@NobleBumblebee
Copy link
Contributor Author

Hello, I have a failed check caused by another module, I wasn't working on.

@AtsushiSakai
Copy link
Owner

Thank you for reporting. I will try to fix in #468. Please wait.

@AtsushiSakai
Copy link
Owner

Rerun CI.

@NobleBumblebee
Copy link
Contributor Author

It's all good for the checks. Thank you for solving that issue.

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

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

Thank you for great PR!!. I have a small request. PTAL.

@@ -152,6 +148,29 @@ def main():
print("R:", R)
print("T:", T)

# test for 3d point set
Copy link
Owner

Choose a reason for hiding this comment

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

I think this test for 3d point test should be separated to main(), like main_3d_point() or something. And then iterative_closest_point.py should be updated.

@NobleBumblebee
Copy link
Contributor Author

There is one thing that bothers me. Even if you pass 3d point cloud, the animation would be in 2d (for axis x,y). The code to visualize in 3d will be more complicated. Requiring to put if clause for 2d or 3d case, etc.
Is it ok, that we left 2d animation for both cases?

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

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

Could you please add a new test here which call main_3d_points?

@AtsushiSakai
Copy link
Owner

One idea is we can create a new plot function for 2d points to extract these codes:

plt.cla()
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect(
'key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(previous_points[0, :], previous_points[1, :], ".r")
plt.plot(current_points[0, :], current_points[1, :], ".b")
plt.plot(0.0, 0.0, "xr")
plt.axis("equal")
plt.pause(0.1)

And creating a new plot function for 3d points and dispatch to call which function using a if clause.

Shamil GEMUEV added 5 commits February 11, 2021 16:15
@NobleBumblebee
Copy link
Contributor Author

Can I ask you something? I am new to this style checking. How can I do these checks on my Spyder on Windows 10 before the commits? I always have some style issues.

@NobleBumblebee
Copy link
Contributor Author

So for 3d plots I divided 2d case and 3d case by if-else operator. To my mind it is least dirty.
It is possible to put drawing code to separate functions, but I am afraid it will not look good among functions that implement functionality.
What do you think?

* remove space
@lgtm-com
Copy link

lgtm-com bot commented Feb 11, 2021

This pull request introduces 1 alert when merging 56b319c into b8f28cc - view on LGTM.com

new alerts:

  • 1 for Unused import

@NobleBumblebee
Copy link
Contributor Author

Unused import concerns from mpl_toolkits.mplot3d import Axes3D for 3D plotting. It is needed for 3d scatter drawing but it is never called explicitly.

@AtsushiSakai
Copy link
Owner

How can I do these checks on my Spyder on Windows 10 before the commits? I always have some style issues.

Unfortunately, there is not a way not. But I think the "runtests.sh" should do it locally.
I will try to add it in #481

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

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

Hi. Thank you for your patience. Maybe this is the last review. After addressed my comments, I will merge this PR. PTAL.

Comment on lines 44 to 45
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Copy link
Owner

@AtsushiSakai AtsushiSakai Feb 14, 2021

Choose a reason for hiding this comment

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

Current implementation create a new figure for every iteration. I think it is not good.
So, I propose the figure should be clean up after initialization(see my comment below):

Suggested change
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.cla()

* plot drawing in a separate function for both 2D and 3D versions
* figure creating before while loop
@NobleBumblebee
Copy link
Contributor Author

I tried different options to make a 3d scatter be drawn on the same figure. None of them worked for me. PTAL.
Options I tried:

  • just plt.cla() before drawing scatter
  • no clearing at all
  • axes.clear()
  • All of the above with recreating of axes axes = figure.add_subplot(111, projection='3d')
  • Using figure.show() at the end
  • Using figure.canvas.draw() figure.canvas.flush_events()
    None of if was working for 3d plot. I left some code commented. That may help you. So I left working solution with recreating figure for 3d.

@lgtm-com
Copy link

lgtm-com bot commented Feb 19, 2021

This pull request introduces 1 alert when merging 7aa502c into 58390e7 - view on LGTM.com

new alerts:

  • 1 for Unused import

@NobleBumblebee
Copy link
Contributor Author

We also need to do something with import of from mpl_toolkits.mplot3d import Axes3D as it will continue to produce alerts.

if previous_points.shape[0] == 3:
# axes = figure.axes[0]
# axes.clear()
figure = plt.figure()
Copy link
Owner

@AtsushiSakai AtsushiSakai Feb 20, 2021

Choose a reason for hiding this comment

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

Does this work without figure creation in your environment?

Suggested change
figure = plt.figure()
plt.clf()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For 3d case in Spyder I can see only the first plot with initial point position. And it is not updating.
(Need to mention that for 2d case every single frame of optimization is displayed as a separate image, and not an updated previous)
May be this is the case for Spyder. Does it work for you without creating figure for 3d?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah. In my environment (just run the script from a terminal), it works. I think creating a lot of figures is annoying. Could you try to run the script from terminal?

@AtsushiSakai
Copy link
Owner

One more thing. I think you can run style checker locally with:

  1. pip install pycodestyle
  2. run ././rundiffstylecheck.sh
    Please try it.

@NobleBumblebee
Copy link
Contributor Author

bash rundiffstylecheck.sh didn't worked for me:

rundiffstylecheck.sh start!
--2021-02-22` 15:27:06-- https://github.com/AtsushiSakai/DiffSentinel/archive/v0.1.6%0D.zip%0D

Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-02-22 15:27:06 ERROR 404: Not Found.

.ZIP.or v0.1.6 find or open v0.1.6
rundiffstylecheck.sh: line 6: ./DiffSentinel*/starter.sh: No such file or directory
rundiffstylecheck.sh: line 16: syntax error: unexpected end of file

Calling pycodestyle could be used directly for every single file instead. #481
pycodestyle --show-source --show-pep8 SLAM/iterative_closest_point/iterative_closest_point.py

@NobleBumblebee
Copy link
Contributor Author

Hello @AtsushiSakai , still no answer from you.

There is one thing that bothers me. Even if you pass 3d point cloud, the animation would be in 2d (for axis x,y). The code to visualize in 3d will be more complicated. Requiring to put if clause for 2d or 3d case, etc.
Is it ok, that we left 2d animation for both cases?

As I said at the beginning 3d plots are complicated because of a lot of non evident moments.
I suggest to keep 2d plots for both cases.

@AtsushiSakai
Copy link
Owner

AtsushiSakai commented Mar 20, 2021

I'm sorry I missed your comments.

I suggest to keep 2d plots for both cases.

I think 3d plot is very useful for understanding what is happening in the script and other many examples are already using 3d plot.
If you don't mind, once this PR is merged, I will fix the 3d plot related code. Is it OK for you?

@NobleBumblebee
Copy link
Contributor Author

I commented the part of 3d plots, so that now it works good with 2d plots. I leave the 3d part for you to modify.

Copy link
Owner

@AtsushiSakai AtsushiSakai left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your patience!!

@AtsushiSakai AtsushiSakai merged commit bf2d9df into AtsushiSakai:master Apr 2, 2021
@NobleBumblebee
Copy link
Contributor Author

Thank you too. Please keep me in touch with when you will add 3d plot drawing. I want to see a solution that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ICP support for 3d point clouds
2 participants