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.ABCAn 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.USBCameraA simple async usb camera
gbvision.utils.cameras.camera module¶
-
class
gbvision.utils.cameras.camera.Camera[source]¶ Bases:
gbvision.utils.readable.Readable,abc.ABCAn 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
-
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
-
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:
objectDescribes 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
- focal_length –
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.CameraBehaves 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
-
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
-
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
-
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
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.CameraA 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
-
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
-
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
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.CameraA 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
-
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
-
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
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.ABCA 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)
-
class
gbvision.utils.cameras.streaming_camera.StreamingCamera[source]¶ Bases:
gbvision.utils.cameras.camera.Camera,abc.ABCAn 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
-
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.CameraA 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
-
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
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.USBCameraA simple USB stream camera