Skip to content

Points outside field of view not always filtered out by Camera.inframe #60

Description

@ezwelty

Camera models with large non-linear distortion can sometimes project points outside their field of view onto their image frame. This can lead to artifacts when for example using Camera.project_dem. The workaround I have found is to check whether a point is in the camera frame in normalized camera coordinates, before distortion is applied to the incoming points. The frame (box_xy below) could be pre-computed and cached for speed.

import glimpse
import numpy as np
import shapely
import shapely.geometry

def inframe_xyz(cam: glimpse.Camera, xyz: np.ndarray):
  xy = cam._xyz_to_xy(xyz)
  # Project camera box to camera coordinates and use that to filter points within field of view
  box_uv = cam.edges()
  box_xy = cam._uv_to_xy(box_uv)
  # Test point in polygon
  polygon = shapely.geometry.Polygon(box_xy)
  shapely.prepare(polygon)
  points = shapely.points(xy)
  return shapely.contains(polygon, points)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions