Field-Robotics-Lab / nps_uw_multibeam_sonar

Multibeam sonar plugin with NVIDIA Cuda library
Apache License 2.0
35 stars 20 forks source link

Normal calculation #57

Open 5p00kk opened 6 months ago

5p00kk commented 6 months ago

Hey I have few questions considering the normal calculation:

  1. Normals are estimated here: https://github.com/Field-Robotics-Lab/nps_uw_multibeam_sonar/blob/47dae1f2896ba124e2fb8a10e03109d80f4648cd/src/gazebo_multibeam_sonar_ray_based.cpp#L786-L788

They are based on a Sobel filter of a depth map where each pixel corresponds to distance measured by particular beam not the z value of the camera coordinate system. If I understand correctly during the normal calculation you basically calculate the crossproduct of [1, 0, dzdu dudx] and [0, 1, dzdv dvdy] to get the normal vector. However it seems to me that your z is not actually z but the ray distance that would need to processed through "camera" model to get the z coordinate.

For instance, it seems to me that with such implementation, if the sonar is looking at a parallel plane, each of the rays will return different normal, even though the normal should be same for all and only ray angle should be changing. Please let me know if you can see some holes in my understanding.

  1. Also I'm a bit confused about the change here: https://github.com/Field-Robotics-Lab/nps_uw_multibeam_sonar/blob/47dae1f2896ba124e2fb8a10e03109d80f4648cd/src/sonar_calculation_cuda.cu#L206-L207

what is the reason of dropping the actual incidence angle calculation and replacing it with basically with acos of scaled depth? How does this work?

EDIT: Considering 2, I think I understand now that the normal vector is normalized so by doing acos of the z component you can find the angle between a line parallel to the camera axis and the normal, however this does not take into account the angle of the ray at all, right?

woensug-choi commented 5 months ago

First of all, thank you for looking into this so much deep!

  1. what do you mean by z value? I did want the distance measured by each rays. And I also wanted the ray to return different normal for the parallel plane case. I wanted normals so that I can calculate the angle between the ray emitting direction and the surface normal. Something like how much is it tilted (the incident angle) to calculate reflection loss.

  2. I think as the normal is already calculated in consideration of the angle of the ray?

Hope we can iterate more on this subject! I would love to find bugs! Nobody has reviewed actual code but only final images.

5p00kk commented 5 months ago

Hey, thanks for the response.

  1. With z value I meant the depth in contrast to the ray distance (range). z = rcos(elevation)cos(azimuth). I believe the formula you have then is for the crossproduct of [1, 0, drdx] and [0, 1, drdy,]. Have you looked if the normals that you generate make sense? It seems like this might be an approach it's just hard for me to imagine in my head what is the resulting normal vector here. I think though even if you wanted to calculate drdx and drdy you end up with the "1.0/this->focallength*depth" term which comes from the camera model and there depth should be actual depth (z) not ray distance as you use it.

I'm currently implementing something similar and using this for inspiration and the normal results seemed off to me, I have not made proper tests tho to verify the (in)correctness. I have gone the other way of calculating dzdx dzdy and getting point's normal in camera aligned coordinate frame and then using something like your commented out compute_incidence() to combine ray_direction with normal_direction to get the reflection angle.

I can try to collect some data later to check if there is any issue with the results