mdx.mtmc.utils.viz_mtmc_utils module

get_frame_objects_and_timestamps(frames: List[Frame]) Tuple[Dict[Tuple[str, int, int], Object], Dict[Tuple[str, int], datetime]]

Gets objects and timestamps from frames

Parameters:

frames (List[Frame]) – list of frames

Returns:

dictionaries of objects and timestamps

Return type:

Tuple[Dict[Tuple[str,int,int],Object],Dict[Tuple[str,int],datetime]]

objects, timestamps = get_frame_objects_and_timestamps(frames)
get_predefined_bgr_color(idx: int) Tuple[int, int, int]

Gets pre-defined BGR color

Parameters:

idx (int) – index

Returns:

BGR color

Return type:

Tuple[int, int, int]

b, g, r = get_predefined_bgr_color(idx)
get_random_bgr_color(idx: int, color_gap_min: int = 64) Tuple[int, int, int]

Gets random BGR color

Parameters:
  • idx (int) – index

  • color_gap_min (int) – minimum color gap

Returns:

BGR color

Return type:

Tuple[int, int, int]

b, g, r = get_random_bgr_color(idx, color_gap_min)
hash_behaviors(behaviors: List[Behavior], selected_sensor_ids: List[str], selected_behavior_ids: List[str] = []) Dict[str, Dict[str, Behavior]]

Hashes behaviors to a dict

Parameters:
  • behaviors (List[Behavior]) – list of behaviors

  • selected_sensor_ids (List[str]) – selected sensor IDs

  • selected_behavior_ids (List[str]) – selected behavior IDs

Returns:

hashed dictionary of behaviors

Return type:

Dict[str,Dict[str,Behavior]]

behavior_dict = hash_behaviors(behaviors, selected_sensor_ids, selected_behavior_ids)
hash_frames(frames: List[Frame], selected_sensor_ids: List[str], is_sensor_1st: bool = False) Dict[str, Dict[str, Dict[str, Object]]]

Hashes frames to a dict

Parameters:
  • frames (List[Frame]) – list of frames

  • selected_sensor_ids (List[str]) – selected sensor IDs

  • is_sensor_1st (bool) – is sensor ID the first level

Returns:

hashed dictionary of frames

Return type:

Dict[str,Dict[str,Dict[str,Object]]]

frame_dict = hash_frames(frames, selected_sensor_ids, is_sensor_1st)
hash_ground_truth_bboxes(ground_truths: List[List[str]], selected_sensor_ids: List[str], video_dir_path: str) Dict[str, Dict[str, Dict[str, Object]]]

Hashes ground-truth bounding boxes to a dict

Parameters:
  • ground_truths (List[List[str]]) – list of ground truths

  • selected_sensor_ids (List[str]) – selected sensor IDs

  • video_dir_path (str) – path to the directory of videos

Returns:

hashed dictionary of ground-truth bounding boxes

Return type:

Dict[str,Dict[str,Dict[str,Object]]]

ground_truth_dict = hash_ground_truth_bboxes(ground_truths, selected_sensor_ids, video_dir_path)
hash_ground_truth_locations(ground_truths: List[List[str]], selected_sensor_ids: List[str], video_dir_path: str) Tuple[Dict[str, Dict[str, List[float]]], int]

Hashes ground-truth locations to a dict

Parameters:
  • ground_truths (List[List[str]]) – list of ground truths

  • selected_sensor_ids (List[str]) – selected sensor IDs

  • video_dir_path (str) – path to the directory of videos

Returns:

hashed dictionary of ground-truth locations and max object ID

Return type:

Tuple[Dict[str,Dict[str,List[float]]],int]

ground_truth_dict, max_object_id = hash_ground_truth_locations(ground_truths, selected_sensor_ids, video_dir_path)
hash_mtmc_objects(mtmc_objects: List[MTMCObject], selected_global_ids: List[str]) Dict[str, Dict[str, Behavior]]

Hashes MTMC objects to a dict

Parameters:
  • mtmc_objects (List[MTMCObject]) – list of MTMC objects

  • selected_global_ids (List[str]) – selected global IDs

Returns:

hashed dictionary of matched behaviors

Return type:

Dict[str,Dict[str,Behavior]]

mtmc_object_dict = hash_mtmc_objects(mtmc_objects, selected_global_ids)
map_behaviors_from_keys(behaviors: List[Behavior]) Dict[str, Behavior]

Maps behavior keys to behaviors

Parameters:

behaviors (List[Behavior]) – list of behaviors

Returns:

map from behavior keys to behaviors

Return type:

Dict[str,Behavior]

behavior_dict = map_behaviors_from_keys(behaviors)
plot_frame_label(image_frame: numpy.array, frame_label: str) numpy.array

Plots frame label on a frame image

Parameters:
  • image_frame (np.array) – image frame

  • frame_label (str) – frame label

Returns:

plotted image frame

Return type:

np.array

image_frame = plot_frame_label(image_frame, frame_label)
plot_histograms(x_axis: List[float], arr_neg: numpy.array, arr_pos: numpy.array, interval: float = 0.02, title: str = '', output_dir_path: str = '', mode: str | None = None, labels: List[str] | None = None) None

Plots histograms

Parameters:
  • x_axis (List[float]) – x-axis

  • arr_neg (np.array) – negative array

  • arr_pos (np.array) – positive array

  • interval (float) – interval of the x-axis

  • title (str) – title of the plot

  • output_dir_path (str) – path to the output directory

  • mode (Optional[str]) – histogram mode (mean, median, or individual)

  • labels (Optional[List[str]]) – custom labels

Returns:

None

plot_histograms(x_axis, arr_neg, arr_pos, interval, title, output_dir_path, mode, labels)
plot_object(image_frame: numpy.array, bbox: Bbox, convex_hull: List[int] | None, foot_pixel: List[str], bbox_label: str, bbox_color: Tuple[int, int, int]) numpy.array

Plots an object on a frame image

Parameters:
  • image_frame (np.array) – image frame

  • bbox (Bbox) – bounding box

  • convex_hull (Optional[List[int]]) – convex hull

  • foot_pixel (List[int]) – foot location in pixel

  • bbox_label (str) – bbox label

  • bbox_color (Tuple[int,int,int]) – bbox color

Returns:

plotted image frame

Return type:

np.array

image_frame = plot_object(image_frame, bbox, convex_hull, foot_pixel, bbox_label, bbox_color)
plot_roc(tpr: List[float], fpr: List[float], tpr_optim: float, fpr_optim: float, title: str, output_dir_path: str) None

Plots ROC curve

Parameters:
  • tpr (List[float]) – TPR values

  • fpr (List[float]) – FPR values

  • tpr_optim (float) – optimum TPR value

  • fpr_optim (float) – optimum FPR value

  • title (str) – title of the plot

  • output_dir_path (str) – path to the output directory

Returns:

None

plot_roc(tpr, fpr, tpr_optim, fpr_optim, title, output_dir_path)
smooth_tail(tail: Deque | None, tail_window: int) Deque

Smooths tail by moving averages in both x-axis and y-axis

Parameters:
  • tail (Optional[Deque]) – tail of the object

  • tail_window (int) – window for smoothing the tail

Returns:

moving averages of the tail

Return type:

Deque

smoothed_tail = smooth_tail(tail, tail_window)