gbvision.tools package¶
Submodules¶
gbvision.tools.drawing_tools module¶
-
gbvision.tools.drawing_tools.draw_text(frame: Optional[numpy.ndarray], text: str, coords: Tuple[int, int], font_scale: Union[int, float], color: Tuple[int, int, int], font=0, *args, **kwargs) → Optional[numpy.ndarray][source]¶ Draws the text on a copy of the frame and returns the copy
Parameters: - frame – The frame to draw on
- text – The text to draw
- coords – The coordinates of the bottom-left corner of the text
- font_scale – The size of the drawn text (multiplied by the default size of the font)
- color – The color to draw the text in
- font – The font, an opencv font constant, default is cv2.FONT_HERSHEY_SIMPLEX
- args – Additional arguments to cv2.putText
- kwargs – Additional keyword arguments to cv2.putText (such as thickness)
Returns: A copy of the frame with the text drawn on it
gbvision.tools.finding_tools module¶
-
gbvision.tools.finding_tools.distance_from_object(loc: Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray]) → float[source]¶ the absolute distance from the camera to this object
Parameters: loc – the object’s location (2d or 3d) Returns: the absolute distance (float)
-
gbvision.tools.finding_tools.plane_angle_by_location(loc: Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray]) → float[source]¶ calculates the angle from the camera to the object’s projection on the x-z plane (y=0 plane)
Parameters: loc – the 3d location Returns: the angle (in radians)
-
gbvision.tools.finding_tools.plane_distance_from_object(loc: Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray]) → float[source]¶ calculates the distance from the object’s projection on the x-z plane (y=0 plane) the distance on the y axis is ignored in this calculation
Parameters: loc – the 3d location Returns: the distance without regarding the y axis
-
gbvision.tools.finding_tools.viewing_angle_of_object(part1: Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray], part2: Union[Tuple[Union[int, float], Union[int, float], Union[int, float]], numpy.ndarray], x_distance: float) → float[source]¶ finds the viewing angle of an object based on a split of the object to two parts (part1 and part2), and the x distance between those two parts in real life (in meters)
Parameters: - part1 – the first part of the object (the left one)
- part2 – the second part of the object (the right one)
- x_distance – the distance between the two objects in meters
Returns: the viewing angle of the object
gbvision.tools.image_tools module¶
-
gbvision.tools.image_tools.crop(frame: Optional[numpy.ndarray], x: int, y: int, w: int, h: int) → Optional[numpy.ndarray][source]¶ crops the image from (x, y) to (x+w, y+h)
Parameters: - frame – the frame to crop
- x – the x coordinate to crop from
- y – the y coordinate to crop from
- w – the width of the cropped image
- h – the height of the cropped image
Returns: the cropped image
-
gbvision.tools.image_tools.median_threshold(frame: Optional[numpy.ndarray], stdv: Union[int, float, numpy.ndarray], box: Union[None, Tuple[int, int, int, int]] = None, color_encoding='BGR') → gbvision.utils.thresholds.threshold.Threshold[source]¶ finds a threshold using the median threshold method the median threshold method defines the lower bounds of the threshold as the median of a given region of the image minus some deviation variable, and the upper bounds as the same median plus the deviation variable in a mathematical term, the threshold is defined to be [median(X) - V, median(X) + V] where X is the frame region and V is the deviation variable
Parameters: - frame – the frame
- stdv – the deviation variable, can be a scalar (same deviation for every channel) or a numpy array with the same size as the number of channels in the threshold, the deviation will be defined for each channel separately
- box – optional, a sub region of the frame from which the median is calculated, when set to None the median is calculated from the entire frame
- color_encoding – the type of color encoding the threshold should use, default is BGR
Returns: a Threshold object
gbvision.tools.list_tools module¶
-
gbvision.tools.list_tools.split_list(f: Callable[[T], int], lst: Iterable[T], amount=2)[source]¶ splits the list into several list according to the function f
Parameters: - lst – the list to split
- f – a function which maps from an argument to the index of the list it should go to for example if we wanted a function to split a list into a list of positive and negative number f could look like lambda x: int(x >= 0)
- amount – the amount of lists to split the data to (2 by default)
Returns: a tuple of all the lists created,
gbvision.tools.math_tools module¶
-
gbvision.tools.math_tools.almost_equal(x: Union[int, float], y: Union[int, float], delta: Union[int, float] = 0.001) → bool[source]¶ Checks if two numbers are almost equal using the formula -delta <= x - y <= delta
Parameters: - x – The first number
- y – The second number
- delta – The maximum allowed diff (default 0.001)
Returns: True if the numbers are almost equal, False otherwise