Pinhole Projection

~10 mincode completion

Implement project_pinhole(points, f) on an (N, 3) array of and return an (N, 2) array of .

Examples

f=2, (2, 4, 2) projects to (2, 4)

Input
project_pinhole([[2, 4, 2]], 2)
Output
[[2, 4]]

The same XY twice as far halves the image coordinates

Input
project_pinhole([[2, 4, 4]], 2)
Output
[[1, 2]]

A point on the optical axis stays at the origin

Input
project_pinhole([[0, 0, 5]], 10)
Output
[[0, 0]]

Hints

Hint 1

The reduction runs across each row, so pass .

Hint 2

A common slip here: multiplied by z instead of dividing.

Requirements

  • points: array of shape (N, 3) with columns X, Y, Z

  • f: focal length (same units as X, Y, Z)

  • Return array of shape (N, 2) with columns x, y

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

8 employers weight this skill

4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 93.

Python
import numpy as np


def project_pinhole(points, f):
    """
    Perspective-project 3D points with a pinhole camera.

    Args:
        points: array of shape (N, 3) with columns X, Y, Z
        f:      focal length (same units as X, Y, Z)

    Returns:
        array of shape (N, 2) with columns x, y
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.