PIXELBANKv9.1.0
Menu

Implement a function to determine if a 3D point is visible from a camera, which is crucial in Structure from Motion and SLAM applications. This involves checking if the point is in front of the camera and its projection falls within the image bounds.

The concept of point visibility is rooted in projective geometry, where a 3D point X,Y,ZX, Y, Z is projected onto a 2D image plane using the camera's intrinsic matrix. For a point to be visible, it must satisfy two conditions: having a positive depth Zcam>0Z_{cam} > 0 and having its projected pixel coordinates u,vu, v within the image dimensions 0≤u<w0 \leq u < w and 0≤v<h0 \leq v < h.

Here are the steps to check point visibility:

  1. Verify the point's depth is positive.
  2. Project the 3D point onto the 2D image plane.
  3. Check if the projected pixel coordinates are within the image bounds.
u=K11X+K13ZZv=K22Y+K23ZZ\begin{aligned} u &= \frac{K_{11}X + K_{13}Z}{Z} \\ v &= \frac{K_{22}Y + K_{23}Z}{Z} \end{aligned}

This technique is widely used in computer vision for tasks like bundle adjustment and triangulation.

Example:

Input:
is_visible([0, 0, 10], (640, 480), [[500,0,320],[0,500,240],[0,0,1]])
Output:
True
Reasoning:

Checking visibility of point (0, 0, 10):

  1. Depth check: Z = 10 > 0 ✓ (in front of camera)
  2. Projection: u = (500×0 + 320×10)/10 = 320 v = (500×0 + 240×10)/10 = 240
  3. Bounds check: 0 ≤ 320 < 640 ✓, 0 ≤ 240 < 480 ✓ Point is visible.

Constraints:

  • point_3d: [X, Y, Z] in camera coordinates
  • image_size: (width, height) in pixels
  • K: 3x3 intrinsic matrix
  • Return True if point is visible
🔒

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

0/0
Run code to see test results.