Pupil Labs Camera¶
This repo contains functionality around the usage of camera intrinsics for undistorting data, projecting and unprojecting points.
It is mostly a wrapper around OpenCV's functionality, providing type hints, input validation, a more intuitive interface, and a few performance optimizations.
Installation¶
pip install pupil-labs-camera
or
pip install -e git+https://github.com/pupil-labs/pl-camera.git
Quick Start¶
The following code demonstrates how to use the library in the context of a Neon recording to undistort an image and 2D gaze points. Additional examples can be found in the example Jupyter Notebook.
import cv2
from pupil_labs import neon_recording as nr
from pupil_labs.camera import Camera
recording = nr.NeonRecording(
"/path/to/recording"
)
camera = Camera(
pixel_width=1600,
pixel_height=1200,
camera_matrix=recording.calibration.scene_camera_matrix,
distortion_coefficients=recording.calibration.scene_distortion_coefficients,
)
data = zip(recording.scene, recording.gaze.sample(recording.scene.time))
for scene_frame, gaze_sample in data:
distorted_image = scene_frame.bgr
undistorted_image = camera.undistort_image(distorted_image)
distorted_gaze = gaze_sample.point
undistorted_gaze = camera.undistort_points(distorted_gaze)
cv2.circle(
distorted_image,
tuple(map(int, distorted_gaze)),
radius=25,
color=(0, 0, 255),
thickness=5,
)
cv2.circle(
undistorted_image,
tuple(map(int, undistorted_gaze)),
radius=25,
color=(0, 255, 0),
thickness=5,
)
cv2.imshow("Distorted Image", distorted_image)
cv2.imshow("Undistorted Image", undistorted_image)
cv2.waitKey(30)