Background Modules

bg_models.apply_dilation(image, kernel_size, kernel_type)[source]

Apply dilation to image with the specified kernel type and image

Parameters:
  • image – image to which apply opening
  • kernel_size – size of the structuring element
  • kernel_type – structuring element
Returns:

image with opening applied

Return type:

np.uint8

bg_models.apply_opening(image, kernel_size, kernel_type)[source]

Apply opening to image with the specified kernel type and image

Parameters:
  • image – image to which apply opening
  • kernel_size – size of the structuring element
  • kernel_type – structuring element
Returns:

image with opening applied

Return type:

np.uint8

bg_models.compute_background_running_average(frame, average, alpha, holes_frame)[source]

Calculate background using running average technique new background is equal to:

\(bg_{new} = (1-alpha)*bg_{old} + alpha*frame\)
Parameters:
  • frame (np.uint16) – current frame for background update
  • average (np.float32) – background model to update
  • alpha (float) – update learning rate
  • frame_holes_mask (np mask) –
Returns:

updated background model

Return type:

np.float32

bg_models.compute_foreground_mask_from_func(f_bg, current_frame, alpha)[source]

Extract binary foreground mask (1 foreground, 0 background) from f_bg background modeling function and update background model.

Parameters:
  • f_bg – background modeling function
  • current_frame – current frame from which extract foreground
  • alpha – update learning rate
Returns:

foreground mask

Return type:

np.uint8

bg_models.compute_holes_mask_in_frame(frame)[source]
bg_models.cut_foreground(image, mask)[source]

Cut the foreground from the image using the mask supplied

Parameters:
  • image – image from which cut foreground
  • mask – mask of the foreground
Returns:

image with only the foreground

Raise:

IndexError error if the size of the image is wrong

bg_models.get_bounding_boxes(image)[source]

Return Bounding Boxes in the format x,y,w,h where (x,y) is the top left corner

Parameters:image – image from which retrieve the bounding boxes
Returns:bounding boxes list
Return type:list
bg_models.get_bounding_boxes2(image)[source]

Return Bounding Boxes in the format x,y,w,h where (x,y) is the top left corner

Parameters:image – image from which retrieve the bounding boxes
Returns:bounding boxes array, where each element has the form (x, y, w, h, counter) with counter = 1
Return type:np.array