Skip to content

Updated fov_estimator for filtering out isolated points #41

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

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions avstack/modules/perception/fov_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from avstack.geometry import GlobalOrigin3D, Polygon
from avstack.modules import BaseModule
from avstack.utils.decorators import apply_hooks
from collections import defaultdict



class _LidarFovEstimator(BaseModule):
Expand Down Expand Up @@ -97,6 +99,8 @@ def __call__(
z_min=self.z_min,
z_max=self.z_max,
)

self._eliminate_isolated_pts(pc_bev, 10, 30)
Copy link
Member

Choose a reason for hiding this comment

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

Can you make 10 and 30 input parameters to the model so we could tune them if needed? Also provide a description of what they are in the docstring.


# center the lidar data
if centering:
Expand Down Expand Up @@ -152,6 +156,24 @@ def _estimate_fov_from_polar_lidar(
) -> "Polygon":
"""To be implemented in subclass"""
raise NotImplementedError

def _eliminate_isolated_pts(self, pc_bev, m_away, num_pts):
ptMap = defaultdict(int)
Copy link
Member

Choose a reason for hiding this comment

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

Python prefers snake case for variables, i.e. pt_map

usable_pts = []
for p1 in pc_bev.data.x:
Copy link
Member

Choose a reason for hiding this comment

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

You don't actually need the loops to do the distance. You can do broadcasting in numpy to make this much faster. See e.g., https://sparrow.dev/pairwise-distance-in-numpy/

Also note that the distance is commutative, meaning dist(a, b) = dist(b, a) so even if you did need loops, you could make the first loop for i in range(0, len(pc_bev.data.x)) and the second loop for j in range(i, len(pc_bev.data.x)) which would cut out half of the evaluations.

p1x, p1y = p1[0], p1[1]
for p2 in pc_bev.data.x:
p2x, p2y = p2[0], p2[1]
if p1x == p2x and p1y == p2y:
continue
dis = np.linalg.norm([p1x - p2x, p1y - p2y])
if (dis < m_away):
ptMap[(p1x, p1y)] += 1
if (ptMap[(p1x, p1y)] == num_pts):
usable_pts.append([p1x, p1y])
break
usable_pts = np.array(usable_pts)
pc_bev.data.x = usable_pts


@MODELS.register_module()
Expand Down
Loading