gbvision.utils package

Subpackages

Submodules

gbvision.utils.async_readable module

class gbvision.utils.async_readable.AsyncReadable[source]

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

An async readable class that constantly reads on another thread

has_started_reading() → bool[source]

Checks if the async thread has started reading

Returns:True if the async thread started, False otherwise
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

wait_start_reading(wait_time: Union[int, float] = 0.01) → None[source]

Waits until the async thread starts reading

Parameters:wait_time – Amounts of seconds to wait in every check interval, default is 0.01

gbvision.utils.game_object module

class gbvision.utils.game_object.GameObject(root_area: Union[int, float])[source]

Bases: object

constructor of the image object which is an object on field

Parameters:root_area – the square root of the surface area of the object in real life
distance(camera: gbvision.utils.cameras.camera.Camera, root_area: Union[int, float]) → float[source]

Note: this measures the distance between the camera and the object, to use another measuring point calculate the norm of the location

Parameters:
  • camera – the camera, can be either Camera or CameraList
  • root_area – a float representing the square root of the area of the object (in pixels)
Returns:

the norm of the vector between the camera and the object (in meters)

location(camera: gbvision.utils.cameras.camera.Camera, root_area: Union[int, float], center: Tuple[Union[int, float], Union[int, float]]) → Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray][source]

Calculates the 3D location of this object, relative to the camera

Parameters:
  • camera – the camera, can be either Camera or CameraList
  • root_area – a float representing the square root of the area of the object (in pixels)
  • center – the center (x,y) of this object in the frame
Returns:

a 3d vector of the relative [x y z] location between the object and the camera/measuring point (in meters)

gbvision.utils.pipeline module

class gbvision.utils.pipeline.PipeLine(*functions, qualname: Optional[str] = None, module: Optional[str] = None)[source]

Bases: object

A class representing a pipeline of function each function receives one input, which is the output of the previous function in the pipeline pipelines are great for representing a long computer vision function (which is why such functions are called pipelines). the PipeLine class can also be used as a function decorator for example, creating a pipeline that adds 1 to it’s output can be done in two ways: Example:

inc = PipeLine(lambda x: x + 1)
three = inc(2)

or Example:

@PipeLine
def inc(x):
    return x + 1
three = inc(2)

You can create a PipeLine from multiple functions: Example:

open_and_read_file = PipeLine(open, lambda x: x.read())
text = open_and_read_file("file.txt")

You can also inherit from the PipeLine class to make a PipeLine factory: Example:

class Adder(PipeLine):
    def __init__(self, num):
        self.num = num
        PipeLine.__init__(self, self.adding_func)
    def adding_func(self, item):
        return item + self.num

You can also do it like this: Example:

class Adder(PipeLine):
    def __init__(self, num):
        def adding_func(item):
            return item + num

        PipeLine.__init__(self, adding_func)

You can use combine a few PipeLines together to create function composition: Example:

multiply_by_2_then_add_3 = PipeLine(lambda x: x * 2) + PipeLine(lambda x: x + 3)
Parameters:
  • functions – A tuple of functions to run one after the other as a pipeline
  • qualname – Optional. A string that will be the __qualname__ of the pipeline object
  • module – Optional. A string that will be the __module__ of the pipeline object

gbvision.utils.readable module

class gbvision.utils.readable.Readable[source]

Bases: gbvision.utils.releasable.Releasable, abc.ABC

An interface representing an object you can read frames from, such as cameras and streams

get_height() → int[source]
Returns:The height of the frames read by this readable
get_width() → int[source]
Returns:The width of the frames read by this readable
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

gbvision.utils.releasable module

class gbvision.utils.releasable.Releasable[source]

Bases: abc.ABC

An interface representing an object holding some resources, which can be released

is_opened() → bool[source]

Checks if this releasable is open and can be read from

Returns:True if the releasable is opened, False otherwise
release() → None[source]

Closes this releasable and releases it’s resource

gbvision.utils.tracker module

class gbvision.utils.tracker.Tracker(tracker_type: str = 'EMPTY')[source]

Bases: object

A tracker object that tracks a rectangle in a video using an opencv tracking algorithm

Parameters:tracker_type – Tracker algorithm taken from this list: BOOSTING, MIL, KCF, TLD, MEDIANFLOW, GOTURN, MOSSE, CSRT, EMPTY. (Default is EMPTY)
TRACKER_TYPE_BOOSTING = 'BOOSTING'
TRACKER_TYPE_CSRT = 'CSRT'
TRACKER_TYPE_EMPTY = 'EMPTY'
TRACKER_TYPE_GOTURN = 'GOTURN'
TRACKER_TYPE_KCF = 'KCF'
TRACKER_TYPE_MEDIANFLOW = 'MEDIANFLOW'
TRACKER_TYPE_MIL = 'MIL'
TRACKER_TYPE_MOSSE = 'MOSSE'
TRACKER_TYPE_TLD = 'TLD'
init(frame: Optional[numpy.ndarray], rect: Tuple[Union[int, float], Union[int, float], Union[int, float], Union[int, float]]) → bool[source]

Initialize the tracker

Parameters:
  • frame – The frame
  • rect – Given rectangle
Returns:

True if initialization went successfully, False otherwise

update(frame: Optional[numpy.ndarray]) → Tuple[Union[int, float], Union[int, float], Union[int, float], Union[int, float]][source]

Get the rect location in new frame

Parameters:frame – The frame
Returns:The location of the rect in new frame

Module contents