v9.1.1
Menu

Map Point Visibility Test

Implement a visibility test for map points in visual SLAM to determine if a point is visible from a given camera pose. This involves evaluating the point's projection onto the image plane and checking various conditions for visibility.

The concept of visibility is crucial in SLAM as it allows for efficient tracking of map points by only considering those that are currently visible. A map point is considered visible if it has a positive depth value and projects within the image bounds. The pinhole camera model is often used to describe this projection, where a 3D point PP is projected onto the image plane using the camera's intrinsic parameters KK and extrinsic parameters RR and tt.

To determine visibility, the following steps are taken:

  1. Transform the map point to the camera's coordinate system using Pcam=R⋅P+tP_{cam} = R \cdot P + t.
  2. Check if the point has a positive depth value.
  3. Project the point onto the image plane using p=K⋅Pcamp = K \cdot P_{cam}.
  4. Calculate the image coordinates u=p0p2u = \frac{p_0}{p_2} and v=p1p2v = \frac{p_1}{p_2}.
  5. Check the bounds: 0≤u<W0 \le u < W and 0≤v<H0 \le v < H, where image_size is (H,W)(H, W).
Pcam=R⋅P+tp=K⋅Pcamu=p0p2v=p1p2\begin{aligned} P_{cam} &= R \cdot P + t \\ p &= K \cdot P_{cam} \\ u &= \frac{p_0}{p_2} \\ v &= \frac{p_1}{p_2} \end{aligned}

Output

Return a dict with:

  • 'visible': True only if the depth is positive and (u,v)(u, v) is inside the image.
  • 'projection': [u,v][u, v] rounded to 1 decimal place, or None if the point is not visible.
  • 'depth': the camera-frame depth (the third coordinate of PcamP_{cam}), rounded to 2 decimal places when positive.

This technique is widely used in autonomous vehicles and robotics for SLAM and 3D reconstruction.

Example

Input
map_point = [0, 0, 5]  # 5m in front
camera_pose = [identity_R, zero_t]
K = [[500,0,320],[0,500,240],[0,0,1]]
image_size = (480, 640)
Output
{'visible': True, 'projection': [320, 240], 'depth': 5.0}
Reasoning
  • Inputs: map_point is the world point P=(0,0,5)P = (0, 0, 5); camera_pose holds a rotation R=IR = I and translation t=(0,0,0)t = (0, 0, 0); K has focal length f=500f = 500 and principal point (cx,cy)=(320,240)(c_x, c_y) = (320, 240); image_size is (H,W)=(480,640)(H, W) = (480, 640).
  • To camera frame: Pcam=I⋅(0,0,5)+0=(0,0,5)P_{cam} = I \cdot (0, 0, 5) + 0 = (0, 0, 5). Its third coordinate is the depth, 5>05 > 0: the point is in front of the camera.
  • Project: p=K⋅Pcam=(500⋅0+320⋅5,  500⋅0+240⋅5,  5)=(1600,1200,5)p = K \cdot P_{cam} = (500 \cdot 0 + 320 \cdot 5,\; 500 \cdot 0 + 240 \cdot 5,\; 5) = (1600, 1200, 5), so u=1600/5=320u = 1600 / 5 = 320 and v=1200/5=240v = 1200 / 5 = 240.
  • Bounds: 0≤320<6400 \le 320 < 640 and 0≤240<4800 \le 240 < 480 — inside the image.
  • Output: {'visible': True, 'projection': [320, 240], 'depth': 5.0}. Notice that a point on the optical axis lands exactly on the principal point; moving it to (1,0,5)(1, 0, 5) gives u=320+500⋅15=420u = 320 + 500 \cdot \frac{1}{5} = 420, while (0,0,−5)(0, 0, -5) sits behind the camera and is not visible.

Constraints

  • map_point: 3D point [X, Y, Z]
  • camera_pose: [R, t] camera extrinsics
  • K: Camera intrinsics
  • image_size: (H, W)
  • Return: Dict with 'visible', 'projection', 'depth'

Learn this in

More from CV: Structure from Motion and SLAM

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.