Barcode Class

Barcode Classes

class kalmus.barcodes.Barcode.Barcode(color_metric, frame_type, sampled_frame_rate=1, skip_over=0, total_frames=10, barcode_type=None)[source]

Bases: object

Barcode Class. Base class for ColorBarcode and BrightnessBarcode

Parameters
  • color_metric (str) -- The metric for computing the color of the frame

  • frame_type (str) -- The type of frame sampling

  • sampled_frame_rate (int) -- Frame sample rate: the frame sampled from every sampled_frame_rate.

  • skip_over (int) -- The number of frames to skip with at the beginning of the video

  • total_frames (int) -- The total number of frames (computed) included in the barcode

  • barcode_type (str) -- The type of the barcode

add_meta_data(key, value)[source]

Add the meta information that describes the barcode

Parameters
  • key (str) -- The key for the meta information

  • value (str) -- The value stored in that key

automatic_find_letterbox()[source]

Automatically find the letter box

enable_rescale_frames_in_generation(rescale_factor=1)[source]

Rescale frames with a factor of rescale_factor for all frames processed in barcode generation

Parameters

rescale_factor (float) -- rescale factor

enable_save_frames(sampled_rate=4)[source]

Set the save frame in the generation of barcode to be True. This attribute, saved_frames_in_generation, should only be modified before the generation of barcode. Once the barcode is generated, this attribute should not be changed.

Parameters

sampled_rate (float) -- Save 1 frame every sampled_rate seconds

enable_user_defined_letterbox()[source]

Use the user defined letter box

find_film_letterbox(num_sample=30)[source]

Automatically find the letter box bounds of the film. Function run the get_letter_box_from_frames helper function by num_sample times and take the median of bounds

Parameters

num_sample (int) -- Number of times running the get_letter_box_from_frames

get_barcode()[source]

Return the barcode. If not exist reshape the stored computed colors/brightness first to get the barcode

Returns

Return the barcode

Return type

class:kalmus.barcodes.Barcode.Barcode

get_color_from_frame(frame)[source]

Compute the color of the input frame using the known color metric

Parameters

frame (numpy.ndarray) -- Input frame

Returns

The color of the frame computed using the known color metric

Return type

numpy.ndarray

process_frame(frame)[source]

Process the original frame by cropping out the letter box and resample frame using the given frame type

Parameters

frame (numpy.ndarray) -- Input orignal frame

Returns

The processed and sampled frame

Return type

numpy.ndarray

read_video(video_path_name)[source]

Read in the video from the given path

Parameters

video_path_name (str) -- The path to the video file

remove_letter_box_from_frame(frame)[source]

Remove the letter box from the frame using the known letter box bounds

Parameters

frame (numpy.ndarray) -- Input original frame with letter box

Returns

Cropped frame without letter box

Return type

numpy.ndarray

save_as_json(filename=None)[source]

Save the barcode into the json file

Parameters

filename (str) -- The name of the saved json file

save_frames(cur_used_frame, frame, frame_arr=None)[source]

Private method Save the frame during the generation process. This functions should only be invoked during the generation process.

Parameters
  • cur_used_frame (int) -- How many frames have been read in

  • frame (numpy.ndarray) -- Current frame (original unprocessed frame)

  • frame_arr (list) -- Array that stored the saved frames

set_letterbox_bound(up_vertical_bound, down_vertical_bound, left_horizontal_bound, right_horizontal_bound)[source]

Manually set up the letter box bound of the film

Parameters
  • up_vertical_bound (int) -- The lower vertical bound

  • down_vertical_bound (int) -- The higher vertical bound

  • left_horizontal_bound (int) -- The left vertical bound

  • right_horizontal_bound (int) -- The right vertical bound

kalmus.barcodes.Barcode.foreback_segmentation(frame)[source]

Helper function Segmented the input frame into two parts: foreground and background, using the GrabCut

Parameters

frame (numpy.ndarray) -- Input frame

Returns

1D image of the foreground part of the image, and 1D image of the background part of the image Expected shape== Number of pixels x channels

Return type

(numpy.ndarray, numpy.ndarray)