gbvision.utils.cameras package

Submodules

gbvision.utils.cameras.async_camera module

class gbvision.utils.cameras.async_camera.AsyncCamera[source]

Bases: gbvision.utils.cameras.camera.Camera, gbvision.utils.async_readable.AsyncReadable, abc.ABC

An abstract class that represents an async camera The async camera is similar to a regular camera, but executes the read actions on another thread thus not blocking the processing thread

You will usually want to inherit from this class and from another camera class in order to use the async functionality for example:

Example::
class AsyncUSBCamera(AsyncCamera, USBCamera):
def _read(self) -> Tuple[bool, Frame]:
return USBCamera.read(self)
def __init__(self, port, data=UNKNOWN_CAMERA):
USBCamera.__init__(self, port, data) AsyncCamera.__init__(self)

gbvision.utils.cameras.async_usb_camera module

class gbvision.utils.cameras.async_usb_camera.AsyncUSBCamera(port, data=UNKNOWN_CAMERA)[source]

Bases: gbvision.utils.cameras.async_camera.AsyncCamera, gbvision.utils.cameras.usb_camera.USBCamera

A simple async usb camera

release() → None[source]

. @brief Closes video file or capturing device. . . The method is automatically called by subsequent VideoCapture::open and by VideoCapture . destructor. . . The C function also deallocates memory and clears *capture pointer.

gbvision.utils.cameras.camera module

class gbvision.utils.cameras.camera.Camera[source]

Bases: gbvision.utils.readable.Readable, abc.ABC

An abstract class representing a camera

get_data() → gbvision.utils.cameras.camera_data.CameraData[source]
Returns:this camera’s constant descriptor (must be the real descriptor, can’t be a copy) when the values of this descriptor are changed, the values of the real camera descriptor must also change
get_fps() → Union[int, float][source]

Gets the fps of this camera

Returns:The fps of the camera
get_height() → int[source]
Returns:The height of a frame read from this camera
get_width() → int[source]
Returns:The width of a frame read from this camera
is_opened() → bool[source]

Checks if the camera can be read from

Returns:True if the camera can be read from, otherwise False
rescale(factor: float) → None[source]

Rescale the size of the frames read from this camera by a factor

Parameters:factor – The rescaling factor
resize(fx: float, fy: float) → None[source]

Rescale the size of the frames read from this camera by different width and height factors

Parameters:
  • fx – The width factor
  • fy – The height factor
set_auto_exposure(auto: Union[int, float, bool]) → bool[source]

Sets the camera’s auto exposure

Parameters:auto – the new auto exposure
Returns:True on success, False on failure
set_exposure(exposure: Union[int, float, bool]) → bool[source]

Sets the camera’s exposure

Parameters:exposure – the new exposure
Returns:True on success, False on failure
set_fps(fps: Union[int, float]) → bool[source]

Sets the fps for this camera

Returns:True on success, False otherwise
set_frame_size(width: int, height: int) → None[source]

Reset the width and height of frames read from this camera to given values

Parameters:
  • width – The new width
  • height – The new height

gbvision.utils.cameras.camera_data module

class gbvision.utils.cameras.camera_data.CameraData(focal_length, fov_width, fov_height, pitch_angle=0, yaw_angle=0, roll_angle=0, x_offset=0, y_offset=0, z_offset=0, is_immutable=False, name=None)[source]

Bases: object

Describes constant about a camera in it’s default state used to approximate distance Between the camera and an object seen in a frame

Parameters:
  • focal_length

    The focal length of the camera at it’s default state, in units of pixels can be described as the square root of the amount of pixels an object takes on a frame, multiplied by it’s distance from the camera and divided by the square root of it’s surface

    FOCAL_LENGTH = :math:’ sqrt(P) * D / sqrt(S)’

    where P is the amount of pixels in the frame representing the object, D is the real life distance between the object and the camera S is the real life surface area (in 2d projection) of the object note that this is a constant, whatever object you choose to use, this formula will yield the same result

  • fov_width

    Half the viewing angle of the camera (field of view) in radians, can be calculated by placing an object in front of the camera, so that the entire object is captured and it’s center is at the frame’s center. the tangent of the angle can be described as the width of the object in real life, divided by the product of the object’s distance from the camera in real life and the ratio between the width of the frame in pixels and the width of the object in the frame, also in pixels

    math:: tan(FOV) = (Wm) / (D * (Wp/Wf))

    where Wm is the real life width of the object D is the real life distance between the object and the camera Wp is the width of the object in the frame (pixels unit) Wf is the width of the frame (pixels unit) to calculate the FOV just apply the inverse tangent

    FOV = math:: arctan(tan(FOV))

  • fov_height – Same as fov_width but on the height/y axis
  • yaw_angle – The clockwise yaw angle (in radians) in which the camera is rotated, the yaw angle is the angle around the y axis, it’s output only affects the x and z axises. set this variable when the camera is rotated around the y axis and you want the output of finder functions to represent the original space, rather then the rotated one.
  • pitch_angle – The clockwise pitch angle (in radians) in which the camera is rotated, the pitch angle is the angle around the x axis, it’s output only affects the y and z axises. set this variable when the camera is rotated around the x axis and you want the output of finder functions to represent the original space, rather then the rotated one.
  • roll_angle – The clockwise roll angle (in radians) in which the camera is rotated, the roll angle is the angle around the z axis, it’s output only affects the x and y axises. set this variable when the camera is rotated around the z axis and you want the output of finder functions to represent the original space, rather then the rotated one.
  • x_offset – The x offset in which the camera is placed the distance from the measuring point (usually the center of the robot) to the camera on the x axis (left/right), if the camera is to the right this should be positive and if it is left this should be negative
  • y_offset – The y offset in which the camera is placed the distance from the measuring point to the camera on the y axis (up/down), if the camera is above the measuring point this variable should be positive and if it is below this should be negative
  • z_offset – The z offset in which the camera is placed the distance from the measuring point to the camera on the z axis (depth), if the camera is placed outer then the measuring point this variable should be positive and if it is inner this should be negative
  • is_immutable – Determines whether the camera data object’s values are immutable (True) or mutable (False)
as_immutable() → gbvision.utils.cameras.camera_data.CameraData[source]

creates and returns an immutable copy of this camera data if this instance is already immutable it will return this instance

Returns:an instance of CameraData, with the same values as this instance but immutable
copy() → gbvision.utils.cameras.camera_data.CameraData[source]

creates a mutable copy of this and returns it :return:

is_immutable() → bool[source]

checks if this camera data instance is immutable

Returns:True if this is immutable, False otherwise
move_x(x: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

moves this camera data’s x axis offset

Parameters:x – the x offset to move by
Returns:a camera data instance with the same params as this but with the x axis moved if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
move_y(y: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

moves this camera data’s y axis offset

Parameters:y – the y offset to move by
Returns:a camera data instance with the same params as this but with the y axis moved if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
move_z(z: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

moves this camera data’s z axis offset

Parameters:z – the z offset to move by
Returns:a camera data instance with the same params as this but with the z axis moved if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
rotate_pitch(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

rotates the camera’s angle around the pitch axis (the x axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the pitch angle rotated if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
rotate_roll(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

rotates the camera’s angle around the roll axis (the z axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the roll angle rotated if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
rotate_yaw(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

rotates the camera’s angle around the yaw axis (the y axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the yaw angle rotated if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_pitch_angle(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

sets the camera’s angle around the pitch axis (the x axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the pitch angle changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_roll_angle(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

sets the camera’s angle around the roll axis (the z axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the roll angle changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_x_offset(x: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

sets this camera data’s x axis offset

Parameters:x – the new x offset
Returns:a camera data instance with the same params as this but with the x axis changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_y_offset(y: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

sets this camera data’s y axis offset

Parameters:y – the new y offset
Returns:a camera data instance with the same params as this but with the y axis changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_yaw_angle(angle: float) → gbvision.utils.cameras.camera_data.CameraData[source]

sets the camera’s angle around the yaw axis (the y axis)

Parameters:angle – the rotation angle
Returns:a camera data instance with the same params as this but with the yaw angle changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it
set_z_offset(z: Union[int, float]) → gbvision.utils.cameras.camera_data.CameraData[source]

sets this camera data’s z axis offset

Parameters:z – the new z offset
Returns:a camera data instance with the same params as this but with the z axis changed if this is immutable it will return a copy of this, otherwise it will modify this instance and return it

gbvision.utils.cameras.camera_list module

class gbvision.utils.cameras.camera_list.CameraList(cameras: List[gbvision.utils.cameras.camera.Camera], select_cam: Optional[int] = None)[source]

Bases: gbvision.utils.cameras.camera.Camera

Behaves as both a camera and a list of cameras camera list holds in it a list of cameras referenced as the field cameras and also a single camera to be the current camera used for every operation on the camera list as a single camera

Parameters:
  • cameras – List of the cameras which will be part of the camera list you can also add and remove cameras later using the
  • select_cam – Optional, an initial camera to be selected, if not set default camera is the first one in the list
add_camera(cam: gbvision.utils.cameras.camera.Camera)[source]

Adds a new camera to the end of the list

Parameters:cam – The new camera
default()[source]

Sets the selected camera to the default camera (first camera in the list)

get_data(foreach=False) → Union[gbvision.utils.cameras.camera_data.CameraData, Generator[gbvision.utils.cameras.camera_data.CameraData, Any, None]][source]
Returns:this camera’s constant descriptor (must be the real descriptor, can’t be a copy) when the values of this descriptor are changed, the values of the real camera descriptor must also change
get_fps(foreach=False) → Union[int, float, Generator[Union[int, float], Any, None]][source]

Gets the fps of this camera

Returns:The fps of the camera
get_height(foreach=False) → Union[int, Generator[int, Any, None]][source]
Returns:The height of a frame read from this camera
get_width(foreach=False) → Union[int, Generator[int, Any, None]][source]
Returns:The width of a frame read from this camera
is_opened(foreach=False) → Union[bool, Generator[bool, Any, None]][source]

Checks if the camera can be read from

Returns:True if the camera can be read from, otherwise False
is_streaming(foreach=False) → Union[bool, Generator[bool, Any, None]][source]
read(foreach=False) → Union[Tuple[bool, Optional[numpy.ndarray]], Generator[Tuple[bool, Optional[numpy.ndarray]], Any, None]][source]

Reads from the readable and returns the result

Returns:False, None if the operation was unsuccessful, else True, frame_result
release(foreach=False)[source]

Closes this releasable and releases it’s resource

rescale(factor, foreach=False)[source]

Rescale the size of the frames read from this camera by a factor

Parameters:factor – The rescaling factor
resize(x_factor, y_factor, foreach=False)[source]

Rescale the size of the frames read from this camera by different width and height factors

Parameters:
  • fx – The width factor
  • fy – The height factor
select_camera(index: int)[source]

Sets the selected camera to be the camera at the index

Parameters:index – The new selected camera’s index
set_auto_exposure(auto, foreach=False) → Union[bool, List[bool]][source]

Sets the camera’s auto exposure

Parameters:auto – the new auto exposure
Returns:True on success, False on failure
set_exposure(exposure, foreach=False) → Union[bool, List[bool]][source]

Sets the camera’s exposure

Parameters:exposure – the new exposure
Returns:True on success, False on failure
set_fps(fps, foreach=False) → Union[bool, List[bool]][source]

Sets the fps for this camera

Returns:True on success, False otherwise
set_frame_size(width, height, foreach=False)[source]

Reset the width and height of frames read from this camera to given values

Parameters:
  • width – The new width
  • height – The new height
toggle_stream(should_stream, foreach=False)[source]

gbvision.utils.cameras.empty_camera module

class gbvision.utils.cameras.empty_camera.EmptyCamera(data: gbvision.utils.cameras.camera_data.CameraData, width: int, height: int)[source]

Bases: gbvision.utils.cameras.camera.Camera

A camera class used for testing, it cannot be read from but can be used for location finding with finders and game objects, also used for measuring of distances when using streams instead of cameras to read frames

Parameters:
  • data – The camera’s CameraData object, should match the fake camera’s data
  • width – The width of a frame read from the fake camera
  • height – The height of a frame read from the fake camera
get_data() → gbvision.utils.cameras.camera_data.CameraData[source]
Returns:this camera’s constant descriptor (must be the real descriptor, can’t be a copy) when the values of this descriptor are changed, the values of the real camera descriptor must also change
get_fps()[source]

Gets the fps of this camera

Returns:The fps of the camera
get_height() → int[source]
Returns:The height of a frame read from this camera
get_width() → int[source]
Returns:The width of a frame read from this camera
is_opened() → bool[source]

Checks if the camera can be read from

Returns:True if the camera can be read from, otherwise False
read() → Tuple[bool, Optional[numpy.ndarray]][source]

Reads from the readable and returns the result

Returns:False, None if the operation was unsuccessful, else True, frame_result
release()[source]

Closes this releasable and releases it’s resource

set_auto_exposure(auto: Union[int, float, bool]) → bool[source]

Sets the camera’s auto exposure

Parameters:auto – the new auto exposure
Returns:True on success, False on failure
set_exposure(exposure: Union[int, float, bool]) → bool[source]

Sets the camera’s exposure

Parameters:exposure – the new exposure
Returns:True on success, False on failure
set_fps(fps)[source]

Sets the fps for this camera

Returns:True on success, False otherwise

gbvision.utils.cameras.stream_camera module

class gbvision.utils.cameras.stream_camera.StreamCamera(data: gbvision.utils.cameras.camera_data.CameraData, stream_receiver: gbvision.utils.net.stream_receiver.StreamReceiver)[source]

Bases: gbvision.utils.cameras.camera.Camera

A camera class which receives it’s frames from a stream receiver

Parameters:
  • data – The camera’s CameraData object, should match the remote camera’s data
  • stream_receiver – The stream receiver to use
get_data() → gbvision.utils.cameras.camera_data.CameraData[source]
Returns:this camera’s constant descriptor (must be the real descriptor, can’t be a copy) when the values of this descriptor are changed, the values of the real camera descriptor must also change
get_fps() → int[source]

Gets the fps of this camera

Returns:The fps of the camera
get_height() → int[source]
Returns:The height of a frame read from this camera
get_width() → int[source]
Returns:The width of a frame read from this camera
is_opened() → bool[source]

Checks if the camera can be read from

Returns:True if the camera can be read from, otherwise False
read() → Tuple[bool, Optional[numpy.ndarray]][source]

Reads from the readable and returns the result

Returns:False, None if the operation was unsuccessful, else True, frame_result
release() → None[source]

Closes this releasable and releases it’s resource

set_auto_exposure(auto: Union[int, float, bool]) → bool[source]

Sets the camera’s auto exposure

Parameters:auto – the new auto exposure
Returns:True on success, False on failure
set_exposure(exposure: Union[int, float, bool]) → bool[source]

Sets the camera’s exposure

Parameters:exposure – the new exposure
Returns:True on success, False on failure
set_fps(fps: int) → bool[source]

Sets the fps for this camera

Returns:True on success, False otherwise

gbvision.utils.cameras.streaming_camera module

class gbvision.utils.cameras.streaming_camera.SimpleStreamingCamera(broadcaster: gbvision.utils.net.stream_broadcaster.StreamBroadcaster, should_stream=False)[source]

Bases: gbvision.utils.cameras.streaming_camera.StreamingCamera, abc.ABC

A simple abstract camera that uses a gbvision.StreamBroadcaster to send streams this class is abstract and cannot exist on it’s own, you must inherit from it and implement the _read method

for example:

Example::
class USBStreamCamera(SimpleStreamCamera, USBCamera):
def _read(self) -> Tuple[bool, Frame]:
return USBCamera.read(self)
def __init__(self, broadcaster, port, data=UNKNOWN_CAMERA):
SimpleStreamCamera.__init__(self, broadcaster) USBCamera.__init__(port, data)
is_streaming()[source]

Checks if the camera is currently streaming

Returns:True if camera is streaming, otherwise False
toggle_stream(should_stream: bool)[source]

Turn on or off the stream feature

Parameters:should_stream – True to activate stream, False to deactivate
class gbvision.utils.cameras.streaming_camera.StreamingCamera[source]

Bases: gbvision.utils.cameras.camera.Camera, abc.ABC

An abstract class that represents a streaming camera The streaming camera is very similar to a regular camera, but has an option which allows it to stream the frames when it reads them

is_streaming() → bool[source]

Checks if the camera is currently streaming

Returns:True if camera is streaming, otherwise False
read()[source]

Reads from the readable and returns the result

Returns:False, None if the operation was unsuccessful, else True, frame_result
toggle_stream(should_stream: bool)[source]

Turn on or off the stream feature

Parameters:should_stream – True to activate stream, False to deactivate

gbvision.utils.cameras.usb_camera module

class gbvision.utils.cameras.usb_camera.USBCamera(port: Union[int, str], data: gbvision.utils.cameras.camera_data.CameraData = UNKNOWN_CAMERA)[source]

Bases: cv2.VideoCapture, gbvision.utils.cameras.camera.Camera

A basic usb connected camera which inherits from cv2 VideoCapture Can also be used to represent a video file instead of a camera

Parameters:
  • port – The usb port to which the camera is connected (or path to the video file)
  • data – The camera data object that describes this camera
get_data()[source]
Returns:this camera’s constant descriptor (must be the real descriptor, can’t be a copy) when the values of this descriptor are changed, the values of the real camera descriptor must also change
get_fps()[source]

Gets the fps of this camera

Returns:The fps of the camera
get_height()[source]
Returns:The height of a frame read from this camera
get_width()[source]
Returns:The width of a frame read from this camera
is_opened() → bool[source]

Checks if the camera can be read from

Returns:True if the camera can be read from, otherwise False
set_auto_exposure(auto) → bool[source]

Sets the camera’s auto exposure

Parameters:auto – the new auto exposure
Returns:True on success, False on failure
set_exposure(exposure) → bool[source]

Sets the camera’s exposure

Parameters:exposure – the new exposure
Returns:True on success, False on failure
set_fps(fps)[source]

Sets the fps for this camera

Returns:True on success, False otherwise

gbvision.utils.cameras.usb_streaming_camera module

class gbvision.utils.cameras.usb_streaming_camera.USBStreamingCamera(broadcaster, port, should_stream=False, data=UNKNOWN_CAMERA)[source]

Bases: gbvision.utils.cameras.streaming_camera.SimpleStreamingCamera, gbvision.utils.cameras.usb_camera.USBCamera

A simple USB stream camera

release() → None[source]

Closes this releasable and releases it’s resource

Module contents