Skip to content

Camera

Backend functionality for cameras

[source]

Camera class

paz.backend.camera.Camera(device_id=0, name='Camera', intrinsics=None, distortion=None)

Camera abstract class. By default this camera uses the openCV functionality. It can be inherited to overwrite methods in case another camera API exists.


Camera methods

[source]

is_open

is_open()

Checks if camera is open.

Returns

Boolean


[source]

start

start()

Starts capturing device

Returns

Camera object.


[source]

stop

stop()

Stops capturing device.


[source]

intrinsics_from_HFOV

intrinsics_from_HFOV(HFOV=70, image_shape=None)

Computes camera intrinsics using horizontal field of view (HFOV).

Arguments

  • HFOV: Angle in degrees of horizontal field of view.
  • image_shape: List of two floats [height, width].

Returns

camera intrinsics array (3, 3).

Notes:

       \           /      ^
        \         /       |
         \ lens  /        | w/2

horizontal field \ / alpha/2 | of view (alpha)_( )/______ | image /( )\ | plane / <-- f --> | / \ | / \ | / \ v

Pinhole camera model

From the image above we know that: tan(alpha/2) = w/2f -> f = w/2 * (1/tan(alpha/2))

alpha in webcams and phones is often between 50 and 70 degrees. -> 0.7 w <= f <= w


[source]

take_photo

take_photo()

Starts camera, reads buffer and returns an image.


[source]

VideoPlayer class

paz.backend.camera.VideoPlayer(image_size, pipeline, camera, topic='image')

Performs visualization inferences in a real-time video.

Properties

  • image_size: List of two integers. Output size of the displayed image.
  • pipeline: Function. Should take RGB image as input and it should output a dictionary with key 'image' containing a visualization of the inferences. Built-in pipelines can be found in paz/processing/pipelines.

Methods

run() record()


VideoPlayer methods

[source]

step

step()

Runs the pipeline process once

Returns

Inferences from pipeline.


[source]

run

run()

Opens camera and starts continuous inference using pipeline, until the user presses q inside the opened window.


[source]

record

record(name='video.avi', fps=20, fourCC='XVID')

Opens camera and records continuous inference using pipeline.

Arguments

  • name: String. Video name. Must include the postfix .avi.
  • fps: Int. Frames per second.
  • fourCC: String. Indicates the four character code of the video.

e.g. XVID, MJPG, X264.


[source]

record_from_file

record_from_file(video_file_path, name='video.avi', fps=20, fourCC='XVID')

Load video and records continuous inference using pipeline.

Arguments

  • video_file_path: String. Path to the video file.
  • name: String. Output video name. Must include the postfix .avi.
  • fps: Int. Frames per second.
  • fourCC: String. Indicates the four character code of the video.

e.g. XVID, MJPG, X264.