tracklab.utils package
- class tracklab.utils.KeypointsDataFrameAccessor(pandas_obj)[source]
Bases:
object
- class tracklab.utils.KeypointsSeriesAccessor(pandas_obj)[source]
Bases:
object
Submodules
tracklab.utils.collate module
tracklab.utils.coordinates module
- tracklab.utils.coordinates.clip_bbox_ltrb_to_img_dim(bbox_ltrb, img_w, img_h)[source]
Clip bounding box to image dimensions. :param bbox_ltrb: bounding box, shape (4,) :type bbox_ltrb: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int
- Returns:
clipped bounding box, shape (4,)
- Return type:
bbox_ltrb (np.ndarray)
- tracklab.utils.coordinates.clip_bbox_ltwh_to_img_dim(bbox_ltwh, img_w, img_h)[source]
Clip bounding box to image dimensions. :param bbox_ltwh: bounding box, shape (4,) :type bbox_ltwh: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int
- Returns:
clipped bounding box, shape (4,)
- Return type:
bbox_ltwh (np.ndarray)
- tracklab.utils.coordinates.clip_bbox_ltwh_to_img_dim_old(bbox_ltwh, img_w, img_h)[source]
Clip bounding box to image dimensions. :param bbox_ltwh: bounding box, shape (4,) :type bbox_ltwh: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int
- Returns:
clipped bounding box, shape (4,)
- Return type:
bbox_ltwh (np.ndarray)
- tracklab.utils.coordinates.clip_keypoints_to_image(kps, image_size)[source]
Clip keypoints to image size.
Parameters: - kps: a tensor/array of size 17x3 representing keypoints.
Can be either a numpy array or a torch tensor.
image_size (tuple): a tuple containing the width and height of the target image.
Returns: - clipped_kps: keypoints clipped to image size.
Returns in the same format as input (numpy array or torch tensor).
- tracklab.utils.coordinates.generate_bbox_from_keypoints(keypoints, extension_factor, image_shape=None)[source]
Generates a bounding box from keypoints by computing the bounding box of the keypoints and extending it by a factor.
- Parameters:
keypoints (np.ndarray) – A numpy array of shape (K, 3) representing the keypoints in the format (x, y, c).
extension_factor (tuple) – A tuple of float [top, bottom, right&left] representing the factor by which
keypoints. (the bounding box should be extended based on the)
image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).
- Returns:
A numpy array of shape (4,) representing the bounding box in the format (left, top, w, h).
- Return type:
np.ndarray
- tracklab.utils.coordinates.keypoints_in_bbox_coord(kp_xyc_img, bbox_ltwh)[source]
Convert keypoints in image coordinates to bounding box coordinates and filter out keypoints that are outside the bounding box. :param kp_xyc_img: keypoints in image coordinates, shape (K, 2) :type kp_xyc_img: np.ndarray :param bbox_tlwh: bounding box, shape (4,) :type bbox_tlwh: np.ndarray
- Returns:
keypoints in bounding box coordinates, shape (K, 2)
- Return type:
kp_xyc_bbox (np.ndarray)
- tracklab.utils.coordinates.ltrb_to_ltwh(bbox, image_shape=None, rounded=False)[source]
Converts coordinates [left, top, right, bottom] to [left, top, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.
- tracklab.utils.coordinates.ltrb_to_xywh(bbox, image_shape=None, rounded=False)[source]
Converts coordinates [left, top, right, bottom] to [center_x, center_y, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.
- tracklab.utils.coordinates.ltwh_to_ltrb(bbox, image_shape=None, rounded=False)[source]
Converts coordinates [left, top, w, h] to [left, top, right, bottom]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.
- tracklab.utils.coordinates.ltwh_to_xywh(bbox, image_shape=None, rounded=False)[source]
Converts coordinates [left, top, w, h] to [center_x, center_y, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.
- tracklab.utils.coordinates.rescale_keypoints(rf_keypoints, size, new_size)[source]
Rescale keypoints to new size. :param rf_keypoints: keypoints in relative coordinates, shape (K, 2) :type rf_keypoints: np.ndarray :param size: original size, (w, h) :type size: tuple :param new_size: new size, (w, h) :type new_size: tuple
- Returns:
rescaled keypoints in relative coordinates, shape (K, 2)
- Return type:
rf_keypoints (np.ndarray)
- tracklab.utils.coordinates.round_bbox_coordinates(bbox)[source]
Round bounding box coordinates. Round to ceil value to avoid bbox with zero width or height. Because of ceil rounding, resulting bbox may be outside of image. Apply above ‘clip_bbox_ltrb_to_img_dim’ to clip bbox to image dimensions. :param bbox: bounding box, shape (4,), in tlwh or tlbr format :type bbox: np.ndarray
- Returns:
rounded bounding box, shape (4,)
- Return type:
bbox (np.ndarray)
- tracklab.utils.coordinates.sanitize_bbox_ltrb(bbox, image_shape=None, rounded=False)[source]
Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.
- Parameters:
bbox (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format
`[left –
top
right
bottom]`.
image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).
round (bool) – Whether to round the bounding box coordinates, type becomes int.
- Returns:
A numpy array of shape (4,) representing the sanitized bounding box in the format [left, top, right, bottom].
- Return type:
np.ndarray
- tracklab.utils.coordinates.sanitize_bbox_ltwh(bbox: array, image_shape=None, rounded=False)[source]
Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.
- Parameters:
bbox (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format
`[left –
top
width
height]`.
image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).
rounded (bool) – Whether to round the bounding box coordinates, type becomes int.
- Returns:
A numpy array of shape (4,) representing the sanitized bounding box in the format [left, top, width, height].
- Return type:
np.ndarray
- tracklab.utils.coordinates.sanitize_bbox_xywh(bbox, images_shape=None, rounded=False)[source]
Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.
- Parameters:
box (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format
`[x_center –
y_center
width
height]`.
image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).
rounded (bool) – Whether to round the bounding box coordinates, type becomes int.
- Returns:
A numpy array of shape (4,) representing the sanitized bounding box in the format [x_center, y_center, width, height].
- Return type:
np.ndarray
- tracklab.utils.coordinates.sanitize_keypoints(keypoints, image_shape=None, rounded=False)[source]
Sanitizes keypoints by clipping them to the image dimensions and ensuring that their confidence values are valid.
- Parameters:
keypoints (np.ndarray) – A numpy array of shape (K, 2 or 3) representing the keypoints in the format (x, y, (c)).
image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).
rounded (bool) – Whether to round the keypoints to integers.
- Returns:
A numpy array of shape (K, 3) representing the sanitized keypoints in the format (x, y, (c)).
- Return type:
np.ndarray
tracklab.utils.cv2 module
- tracklab.utils.cv2.colored_body_parts_overlay(img, masks, clip=True, interpolation=2, alpha=0.28, mask_threshold=0.0, weight_scale=1, rgb=False)[source]
- tracklab.utils.cv2.draw_bbox(detection, patch, bbox_color, bbox_thickness, text_font, text_scale, text_thickness, text_color, print_confidence=False, print_id=False)[source]
- tracklab.utils.cv2.draw_keypoints(detection, patch, kp_color, kp_radius, kp_thickness, text_font, text_scale, text_thickness, text_color, skeleton_color, skeleton_thickness, print_confidence=False, draw_skeleton=True)[source]
- tracklab.utils.cv2.draw_text(img, text, pos, fontFace, fontScale, thickness, lineType=16, color_txt=(0, 0, 0), color_bg=None, alpha_bg=1.0, alignH='l', alignV='b', darken=1.0)[source]
- tracklab.utils.cv2.overlay_heatmap(img, heatmap, weight=0.5, mask_threshold=0.0, color_map=2, rgb=False)[source]
Overlay a heatmap on an image with given color map. :param img: input image in OpenCV BGR format :param heatmap: heatmap to overlay in float from range 0->1. Will be resized to image size and values clipped to 0->1. :param weight: alpha blending weight between image and heatmap, 1-weight for image and weight for heatmap. Set to -1 to :param use the heatmap as alpha channel.: :param color_map: OpenCV type colormap to use for heatmap. :param mask_threshold: heatmap values below this threshold will not be displayed. :param rgb: if True, the heatmap will be converted to RGB before overlaying.
- Returns:
Image with heatmap overlayed.
tracklab.utils.easyocr module
tracklab.utils.instantiate module
tracklab.utils.monkeypatch_hydra module
tracklab.utils.notebook module
- class tracklab.utils.notebook.TrackEngine(cfg, engine, state, evaluator, dataset)
Bases:
tuple
- cfg
Alias for field number 0
- dataset
Alias for field number 4
- engine
Alias for field number 1
- evaluator
Alias for field number 3
- state
Alias for field number 2
- tracklab.utils.notebook.load_from_overrides(overrides=[]) TrackEngine [source]
Load everything as in main(), but from notebook.
- Use with ::
import os import sys sys.path.append(os.getcwd()+”/..”) from tracklab.utils import load_from_overrides
load_from_overrides([“train_detect=false”])
- Parameters:
overrides – list of strings as used in hydra commandline
- Returns:
a tuple containing : cfg, engine, state, evaluator, dataset
- Return type:
track_engine
tracklab.utils.openmmlab module
tracklab.utils.progressbar module
tracklab.utils.wandb module
- tracklab.utils.wandb.apply_recursively(d, f=<function <lambda>>, filter=<function <lambda>>, always_filter=False)[source]
Apply a function to leaf values of a dict recursively and/or filter dict
- Parameters:
f – function taking the value of a leaf as argument and returning a transformation of that value
filter – condition to apply f to only (sub-)branches of the tree
always_filter – if true filter sub-branches, if false only filter leaves.
- Returns:
transformed and filtered dict