Main modules¶
Katna.video module¶
-
class
Katna.video.
Video
(autoflip_build_path=None, autoflip_model_path=None)[source] Bases:
object
Class for all video frames operations
Parameters: object (class:Object) – base class inheritance -
compress_video
(file_path, force_overwrite=False, crf_parameter=23, output_video_codec='libx264', out_dir_path='', out_file_name='')[source] Function to compress given input file
Parameters: - file_path (str) – Input file path
- force_overwrite (bool, optional) – optional parameter if True then if there is already a file in output file location function will overwrite it, defaults to False
- crf_parameter (int, optional) – Constant Rate Factor Parameter for controlling amount of video compression to be applied, The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. It is recommend to keep this value between 20 to 30 A lower value is a higher quality, you can change default value by changing config.Video.video_compression_crf_parameter
- output_video_codec (str, optional) – Type of video codec to choose, Currently supported options are libx264 and libx265, libx264 is default option. libx264 is more widely supported on different operating systems and platforms, libx265 uses more advanced x265 codec and results in better compression and even less output video sizes with same or better quality. Right now libx265 is not as widely compatible on older versions of MacOS and Widows by default. If wider video compatibility is your goal you should use libx264., you can change default value by changing Katna.config.Video.video_compression_codec
- out_dir_path (str, optional) – output folder path where you want output video to be saved, defaults to “”
- out_file_name (str, optional) – output filename, if not mentioned it will be same as input filename, defaults to “”
Raises: Exception – raises FileNotFoundError Exception if input video file not found, also exception is raised in case output video file path already exist and force_overwrite is not set to True.
Returns: Status code Returns True if video compression was successfull else False
Return type: bool
-
compress_videos_from_dir
(dir_path, force_overwrite=False, crf_parameter=23, output_video_codec='libx264', out_dir_path='', out_file_name='')[source] Function to compress input video files in a folder
Parameters: - dir_path (str) – Input folder path
- force_overwrite (bool, optional) – optional parameter if True then if there is already a file in output file location function will overwrite it, defaults to False
- crf_parameter (int, optional) – Constant Rate Factor Parameter for controlling amount of video compression to be applied, The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. It is recommend to keep this value between 20 to 30 A lower value is a higher quality, you can change default value by changing config.Video.video_compression_crf_parameter
- output_video_codec (str, optional) – Type of video codec to choose, Currently supported options are libx264 and libx265, libx264 is default option. libx264 is more widely supported on different operating systems and platforms, libx265 uses more advanced x265 codec and results in better compression and even less output video sizes with same or better quality. Right now libx265 is not as widely compatible on older versions of MacOS and Widows by default. If wider video compatibility is your goal you should use libx264., you can change default value by changing Katna.config.Video.video_compression_codec
- out_dir_path (str, optional) – output folder path where you want output video to be saved, defaults to “”
Raises: Exception – raises FileNotFoundError Exception if input video file not found, also exception is raised in case output video file path already exist and force_overwrite is not set to True.
Returns: Status code Returns True if video compression was successfull else False
Return type: bool
-
extract_keyframes_from_videos_dir
(no_of_frames, dir_path, writer)[source] Returns best key images/frames from the videos in the given directory. you need to mention number of keyframes as well as directory path containing videos. Function returns python dictionary with key as filepath each dictionary element contains list of python numpy image objects as keyframes.
Parameters: - no_of_frames (int, required) – Number of key frames to be extracted
- dir_path (str, required) – Directory location with videos
- writer (Writer, required) – Writer class obj to process keyframes
Returns: Dictionary with key as filepath and numpy.2darray Image objects
Return type: dict
-
extract_video_keyframes
(no_of_frames, file_path, writer)[source] Returns a list of best key images/frames from a single video.
Parameters: - no_of_frames (int, required) – Number of key frames to be extracted
- file_path (str, required) – video file location
- writer (Writer, required) – Writer object to process keyframe data
Returns: List of numpy.2darray Image objects
Return type: list
-
extract_video_keyframes_big_video
(no_of_frames, file_path)[source] Parameters: - no_of_frames –
- file_path –
Returns: Return type:
-
resize_video
(file_path, abs_file_path_output, aspect_ratio)[source] Resize a single video file
Parameters: - file_path (str) – file path of the video to be resized
- abs_file_path_output (str) – absolute path to output video file
- aspect_ratio ([type]) – aspect ratio of the final video
Raises: Exception – [description]
-
resize_video_from_dir
(dir_path, abs_dir_path_output, aspect_ratio)[source] Resize all videos inside the directory
Parameters: - dir_path (str) – Directory path where videos are located
- abs_dir_path_output (str) – Absolute path to directory where output videos should to be dumped
- aspect_ratio ([type]) – desirable aspect ratio for the videos
Raises: Exception – [description]
-
save_frame_to_disk
(frame, file_path, file_name, file_ext)[source] saves an in-memory numpy image array on drive.
Parameters: - frame (numpy.ndarray, required) – In-memory image. This would have been generated by extract_video_keyframes method
- file_name (str, required) – name of the image.
- file_path (str, required) – Folder location where files needs to be saved
- file_ext (str, required) – File extension indicating the file type for example - ‘.jpg’
Returns: None
-
Katna.image module¶
-
class
Katna.image.
Image
(disable_text=True)[source] Bases:
object
Class for all image cropping operations
Parameters: object (class:Object) – base class inheritance Constructor for image files
-
crop_image
(file_path, crop_width, crop_height, num_of_crops, writer, filters=[], down_sample_factor=8)[source] smartly crops the imaged based on the specification - width and height
Parameters: - file_path (str, required) – Input file path
- crop_width (int) – output crop width
- crop_height (int) – output crop heigh
- num_of_crops (int) – number of crops required
- writer (Writer, required) – writer object to process data
- filters (list (eg. ['text'])) – filters to be applied for cropping(checks if image contains english text and the crop rectangle doesn’t cut the text)
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
Returns: crop list
Return type: list of structure crop_rect
-
crop_image_from_cvimage
(input_image, crop_width, crop_height, num_of_crops, filters=[], down_sample_factor=8)[source] smartly crops the imaged based on the specification - width and height
Parameters: - input_image (numpy array, required) – Input image
- crop_width (int) – output crop width
- crop_height (int) – output crop heigh
- num_of_crops (int) – number of crops required
- filters (list (eg. ['text'])) – filters to be applied for cropping(only returns crops containing english text where the crop rectangle doesn’t cut the text)
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
Returns: crop list
Return type: list of structure crop_rect
-
crop_image_from_dir
(dir_path, crop_width, crop_height, num_of_crops, writer, filters=[], down_sample_factor=8)[source] smartly crops all the images (inside a directory) based on the specification - width and height
Parameters: - dir_path (str, required) – Input Directory path
- crop_width (int) – output crop width
- crop_height (int) – output crop height
- num_of_crops (int) – number of crops required
- writer (int) – number of crops required
- filters (list (eg. ['text'])) – filters to be applied for cropping(checks if image contains english text and the crop rectangle doesn’t cut the text)
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
Returns: crop dict with key as filepath and crop list for the file
Return type: dict
-
crop_image_with_aspect
(file_path, crop_aspect_ratio, num_of_crops, writer, filters=[], down_sample_factor=8)[source] smartly crops the imaged based on the aspect ratio and returns number of specified crops for each crop spec found in the image with the specified aspect ratio
Parameters: - file_path (str, required) – Input file path
- crop_aspect_ratio (str (eg. '4:3')) – output crop ratio
- num_of_crops (Writer, required) – number of crops required
- filters (list (eg. ['text'])) – filters to be applied for cropping(checks if image contains english text and the crop rectangle doesn’t cut the text)
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
- writer – writer to process the image
Returns: crop list
Return type: list of structure crop_rect
-
resize_image
(file_path, target_width, target_height, down_sample_factor=8)[source] smartly resizes the image based on the specification - width and height
Parameters: - file_path (str, required) – Input file path
- target_width (int) – output image width
- target_height (int) – output image height
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
Returns: resized image
Return type: cv_image
-
resize_image_from_dir
(dir_path, target_width, target_height, down_sample_factor=8)[source] smartly resizes all the images (inside a directory) based on the specification - width and height
Parameters: - dir_path (str, required) – Input Directory path
- target_width (int) – output width
- target_height (int) – output height
- down_sample_factor (int [default=8]) – number by which you want to reduce image height & width (use it if image is large or to fasten the process)
Returns: dict with key as filepath and resized image as in opencv format as value
Return type: dict
-
save_crop_to_disk
(crop_rect, frame, file_path, file_name, file_ext, rescale=False)[source] saves an in-memory crop on drive.
Parameters: - crop_rect (crop_rect, required) – In-memory crop_rect.
- frame (numpy.ndarray, required) – In-memory input image.
- file_name (str, required) – name of the image.
- file_path (str, required) – Folder location where files needs to be saved
- file_ext (str, required) – File extension indicating the file type for example - ‘.jpg’
Returns: None
-
save_image_to_disk
(image, file_path, file_name, file_ext)[source] saves an in-memory image obtained from image resize on drive.
Parameters: - image (numpy.ndarray, required) – In-memory input image.
- file_name (str, required) – name of the image.
- file_path (str, required) – Folder location where files needs to be saved
- file_ext (str, required) – File extension indicating the file type for example - ‘.jpg’
Returns: None
-
-
class
Katna.image.
UserFiltersEnum
[source] Bases:
object
Enum class for filters
-
text
= 'TextDetector'
-
Config module¶
-
class
Katna.config.
CropScorer
[source] Bases:
object
-
detail_weight
= 0.2
-
edge_radius
= 0.4
-
edge_weight
= -20
-
face_bias
= 0.01
-
face_weight
= 3.4
-
outside_importance
= -0.5
-
rects_weight
= 1
-
rule_of_thirds
= True
-
saliency_bias
= 0.2
-
saliency_weight
= 1.3
-
-
class
Katna.config.
EdgeFeature
[source] Bases:
object
-
ksize
= 3
-
max_val_threshold
= 200
-
min_val_threshold
= 100
-
-
class
Katna.config.
FaceFeature
[source] Bases:
object
-
cache_subdir
= 'models'
-
confidence
= 0.5
-
model_file
= 'res10_300x300_ssd_iter_140000_fp16.caffemodel'
-
modelfile_download_link
= 'https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20180205_fp16/res10_300x300_ssd_iter_140000_fp16.caffemodel'
-
prototxt_download_link
= 'https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt'
-
prototxt_file
= 'deploy.prototxt'
-
-
class
Katna.config.
FrameExtractor
[source] Bases:
object
-
USE_LOCAL_MAXIMA
= True
-
len_window
= 20
-
max_frames_in_chunk
= 500
-
window_type
= 'hanning'
-
-
class
Katna.config.
Image
[source] Bases:
object
-
DEBUG
= False
-
crop_height_reduction_factor_in_each_iteration
= 0.05
-
down_sample_factor
= 8
-
min_image_to_crop_factor
= 4
-
-
class
Katna.config.
ImageSelector
[source] Bases:
object
-
brightness_step
= 2.0
-
entropy_step
= 0.5
-
max_brightness_value
= 90.0
-
max_entropy_value
= 10.0
-
min_brightness_value
= 10.0
-
min_entropy_value
= 1.0
-
-
class
Katna.config.
MediaPipe
[source] Bases:
object
-
class
AutoFlip
[source] Bases:
object
-
BLUR_AREA_OPACITY
= 0.6
-
BLUR_AREA_OPACITY_KEYNAME
= 'BLUR_AREA_OPACITY'
-
BUILD_CMD
= 'run_autoflip'
-
CONFIG_FILE_PBTXT
= '/home/docs/checkouts/readthedocs.org/user_builds/katna/checkouts/latest/Katna/mediapipe_autoflip.pbtxt'
-
DEFAULT_BLUR_AREA_OPACITY
= 0.6
-
DEFAULT_FEATURE_SIGNAL_VALUE
= 'false'
-
DEFAULT_MOTION_STABALIZATION_THRESHOLD
= 0.5
-
ENFORCE_FEATURES
= {'CAR': False, 'FACE_ALL_LANDMARKS': False, 'FACE_CORE_LANDMARKS': False, 'FACE_FULL': False, 'HUMAN': False, 'OBJECT': False, 'PET': False}
-
ENFORCE_FEATURES_KEYNAME
= 'ENFORCE_FEATURES'
-
MODELS_FOLDER_LOCATION
= '/home/docs/checkouts/readthedocs.org/user_builds/katna/checkouts/latest/docs/source/mediapipe/models'
-
RERUN_LIMIT
= 2
-
STABALIZATION_THRESHOLD
= 0.5
-
STABALIZATION_THRESHOLD_KEYNAME
= 'STABALIZATION_THRESHOLD'
-
TMP_PBTXT_FOLDER_NAME
= 'temp_pbtxt'
-
TMP_PBTXT_FOLDER_PATH
= '/home/docs/checkouts/readthedocs.org/user_builds/katna/checkouts/latest/docs/source/temp_pbtxt'
-
classmethod
get_conf
()[source] Gets the current config
Returns: dictionary containing the current config Return type: dict
-
classmethod
get_pbtxt_mapping
()[source]
-
classmethod
set_conf
(config)[source] Sets the config passed
Parameters: config (dict) – The configuration to set.
-
-
class
-
class
Katna.config.
TextDetector
[source] Bases:
object
-
cache_subdir
= 'models'
-
frozen_weights
= 'frozen_east_text_detection.pb'
-
layerNames
= ['feature_fusion/Conv_7/Sigmoid', 'feature_fusion/concat_3']
-
merge_threshold
= 1
-
min_confidence
= 0.9
-
model_download_link
= 'https://github.com/oyyd/frozen_east_text_detection.pb/raw/master/frozen_east_text_detection.pb'
-
-
class
Katna.config.
Video
[source] Bases:
object
-
DEBUG
= False
-
assumed_no_of_frames_per_candidate_frame
= 5
-
compression_output_file_extension
= 'mp4'
-
memory_consumption_threshold
= 0.8
-
min_video_duration
= 5.0
-
video_compression_codec
= 'libx264'
-
video_compression_crf_parameter
= 23
-
video_extensions
= ['.str', '.aa', '.aac', '.ac3', '.acm', '.adf', '.adp', '.dtk', '.ads', '.ss2', '.adx', '.aea', '.afc', '.aix', '.al', '.ape', '.apl', '.mac', '.aptx', '.aptxhd', '.aqt', '.ast', '.avi', '.avr', '.bfstm', '.bcstm', '.bit', '.bmv', '.brstm', '.cdg', '.cdxl', '.xl', '.c2', '.302', '.daud', '.str', '.dss', '.dts', '.dtshd', '.dv', '.dif', '.cdata', '.eac3', '.paf', '.fap', '.flm', '.flac', '.flv', '.fsb', '.g722', '.722', '.tco', '.rco', '.g723_1', '.g729', '.genh', '.gsm', '.h261', '.h26l', '.h264', '.264', '.avc', '.hevc', '.h265', '.265', '.idf', '.cgi', '.sf', '.ircam', '.ivr', '.flv', '.lvf', '.m4v', '.mkv', '.mk3d', '.mka', '.mks', '.mjpg', '.mjpeg', '.mpo', '.j2k', '.mlp', '.mov', '.mp4', '.m4a', '.3gp', '.3g2', '.mj2', '.mp2', '.mp3', '.m2a', '.mpa', '.mpc', '.mjpg', '.txt', '.mpl2', '.sub', '.msf', '.mtaf', '.ul', '.musx', '.mvi', '.mxg', '.v', '.nist', '.sph', '.nsp', '.nut', '.ogg', '.oma', '.omg', '.aa3', '.pjs', '.pvf', '.yuv', '.cif', '.qcif', '.rgb', '.rt', '.rsd', '.rsd', '.rso', '.sw', '.sb', '.smi', '.sami', '.sbc', '.msbc', '.sbg', '.scc', '.sdr2', '.sds', '.sdx', '.shn', '.vb', '.son', '.sln', '.mjpg', '.stl', '.sub', '.sub', '.sup', '.svag', '.tak', '.thd', '.tta', '.ans', '.art', '.asc', '.diz', '.ice', '.nfo', '.txt', '.vt', '.ty', '.ty+', '.uw', '.ub', '.v210', '.yuv10', '.vag', '.vc1', '.viv', '.idx', '.vpk', '.txt', '.vqf', '.vql', '.vqe', '.vtt', '.wsd', '.xmv', '.xvag', '.yop', '.y4m']
-
video_split_threshold_in_minutes
= 20
-
Helper modules¶
Katna.decorators module¶
-
class
Katna.decorators.
DebugDecorators
[source] Bases:
object
File validation decorator
- Arguments:
- object {[type]} – [description]
- Raises:
- None:
- Returns:
- [] – [Decorated function]
-
classmethod
add_optional_debug_images_for_image_module
(decorated)[source] Add optional debug images in image_module class if DEBUG option is True in config
-
class
Katna.decorators.
FileDecorators
[source] Bases:
object
File validation decorator
Raises: FileNotFoundError – File or path is incorrect -
classmethod
validate_dir_path
(decorated)[source] Validate if the input path is a valid dir or location
Parameters: decorated (function, required) – decorated function Returns: function if the path is valid Return type: function object
-
classmethod
validate_file_path
(decorated)[source] Validate if the input path is a valid file or location
Parameters: decorated (function, required) – decorated function Returns: function if the path is valid Return type: function object
-
classmethod
-
class
Katna.decorators.
VideoDecorators
[source] Bases:
object
File validation decorator
- Arguments:
- object {[type]} – [description]
- Raises:
- FileNotFoundError: [Video File is missing]
- Returns:
- [boolean] – [if the file exists and is valid]
-
classmethod
validate_video
(decorated)[source] Validate if the input video is a valid file
-
Katna.decorators.
exception
(logger)[source] A decorator that wraps the passed in function and logs exceptions should one occur
param logger: The logging object type logger: logger
Internal modules for Video¶
Katna.frame_extractor module¶
-
class
Katna.frame_extractor.
FrameExtractor
[source] Bases:
object
Class for extraction of key frames from video : based on sum of absolute differences in LUV colorspace from given video
-
extract_candidate_frames
(videopath)[source] Pubic function for this module , Given and input video path This functions Returns one list of all candidate key-frames
Parameters: - object (class:Object) – base class inheritance
- videopath (str) – inputvideo path
Returns: opencv.Image.Image objects
Return type: list
-
Katna.image_selector module¶
-
class
Katna.image_selector.
ImageSelector
(n_processes=1)[source] Bases:
object
Class for selection of best top N images from input list of images, Currently following selection method are implemented: brightness filtering, contrast/entropy filtering, clustering of frames and variance of laplacian for non blurred images selection
Parameters: object (class:Object) – base class inheritance -
select_best_frames
(input_key_frames, number_of_frames)[source] [summary] Public function for Image selector class: takes list of key-frames images and number of required frames as input, returns list of filtered keyframes
Parameters: - object (class:Object) – base class inheritance
- input_key_frames (python list opencv images) – list of input keyframes in list of opencv image format
- number_of_frames – Required number of images
Type: int
Returns: Returns list of filtered image files
Return type: python list of images
-
Katna.video_compressor module¶
-
class
Katna.video_compressor.
VideoCompressor
[source] Bases:
object
Class for performing video compression task: based on ffmpeg library for doing video compression
-
compress_video
(file_path, force_overwrite, crf_parameter, output_video_codec, out_dir_path, out_file_name)[source] Function to compress given input file
Parameters: - file_path (str) – Input file path
- force_overwrite (bool, optional) – optional parameter if True then if there is already a file in output file location function will overwrite it, defaults to False
- crf_parameter (int, optional) – Constant Rate Factor Parameter for controlling amount of video compression to be applied, The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. It is recommend to keep this value between 20 to 30 A lower value is a higher quality, you can change default value by changing config.Video.video_compression_crf_parameter
- output_video_codec (str, optional) – Type of video codec to choose, Currently supported options are libx264 and libx265, libx264 is default option. libx264 is more widely supported on different operating systems and platforms, libx265 uses more advanced x265 codec and results in better compression and even less output video sizes with same or better quality. Right now libx265 is not as widely compatible on older versions of MacOS and Widows by default. If wider video compatibility is your goal you should use libx264., you can change default value by changing Katna.config.Video.video_compression_codec
- out_dir_path (str, optional) – output folder path where you want output video to be saved, defaults to “”
- out_file_name (str, optional) – output filename, if not mentioned it will be same as input filename, defaults to “”
Raises: Exception – raises FileNotFoundError Exception if input video file not found, also exception is raised in case output video file path already exist and force_overwrite is not set to True.
Returns: Status code Returns True if video compression was successfull else False
Return type: bool
-
Internal modules for Image¶
Katna.crop_rect module¶
-
class
Katna.crop_rect.
CropRect
(x, y, w, h)[source] Bases:
object
Data structure class for storing image crop rectangles
Parameters: object (class:Object) – base class inheritance -
get_image_crop
(input_image)[source] public functions which for given input image and current crop rectangle object returns image cropped to crop rectangle specifications.
Parameters: - object (class:Object) – base class inheritance
- image (Opencv Numpy Image) – input image
Returns: cropped image according to given spec
Return type: Opencv Numpy Image
-
Katna.crop_extractor module¶
-
class
Katna.crop_extractor.
CropExtractor
[source] Bases:
object
Class for extraction and scoring of all possible crops from input image for input crop size. Currently features being used for scoring a given crop retangle are: Edge, saliency and face detection. Additionally crop scoring also takes following metrics into account: Distance of pixel in crop rectangle from crop boundary and rule of third.
-
extract_candidate_crops
(inputImage, crop_width, crop_height, feature_list)[source] Public Function for crop_extractor module, Given input image and desired crop width and height: function returns list of all candidate crop rectangles scored taking into account input Image Feature list
Parameters: - object (class:Object) – base class inheritance
- inputImage (opencv.Image) – input Image
- crop_width (Int) – input crop width
- crop_height (Int) – input crop height
- feature_list (List of OpenCV numpy image type) – list of input feature maps to be used for scoring a crop rectangle
Returns: List of extracted crop rectangle objects
Return type: list of crop_rect
-
Katna.crop_selector module¶
-
class
Katna.crop_selector.
CropSelector
[source] Bases:
object
Class for selection of top n crop rectangles from input list of crop rectangles ,It also implements filtering functionality, currently following filtering method are implemented: Text Detector filter
Parameters: object (class:Object) – base class inheritance -
select_candidate_crops
(input_image, num_of_crops, input_crop_list, defined_filters, filters=[])[source] Public Function for CropSelector class: takes list of crop rectangles and number of required crops as input and returns list of filtered crop retangles as output. Also takes list of filters to be used for filtering out unwanted crop rectangles as optional input.
Parameters: - object (class:Object) – base class inheritance
- input_image (Opencv Numpy Image) – input image
- input_crop_list (python list crop_rect data structure) – list of input crop in list of crop_rect format
- number_of_crop – Required number of crop
Type: int
Returns: Returns list of filtered crop_rect
Return type: python list of crop_rect data structure
-
Image Filters for Smart Cropping¶
Katna.image_filters.filter¶
Katna.image_filters.text_detector¶
-
class
Katna.image_filters.text_detector.
TextDetector
(weight=1.0)[source] Bases:
Katna.image_filters.filter.Filter
TextDetector Class: Class for implementation of text detector filter, inherit from Filter class
Constructor for this class does following tasks, if not already downloaded , it first downloads text detector dnn weights file from public URL ands save it at USER_HOME/.katna directory, or /tmp/.katna directory. After this initializer code initializes internal parameter: min_confidence (for text detection)
-
download_data
()[source] Public function for downloading the network weight from the URL link, to be used for text detection functionality. Troubleshooting tip: If you get FileNotFound error during text detector initialization, initialize the text detector and call this function directly to download the model file from public URL link.
-
get_filter_result
(crop)[source] Main public function of TextDetector filter class, this filter Returns false if crop contains no text, additionally checks for overlap between input crop rectangle and the detected text bounding box, returns True if No overlap (Filter will not discard input crop) otherwise returns False (signal for discarding input crop).
Parameters: crop (crop_rect) – input crop rectangle to test Returns: True if No overlap (Filter will not discard input crop) otherwise returns False Return type: bool
-
set_image
(image)[source] Public set_image function, This will detect all text boxes in input image and will saves them as internal list of text_rect to be used in get_filter_result
Parameters: image (numpy array(opencv)) – input image from which needs to be cropped
-
Image Features for Smart Cropping¶
Katna.image_features.feature¶
-
class
Katna.image_features.feature.
Feature
(weight)[source] Bases:
object
Base Class: Base class for all Image features: To be used for Katna crop rectangle scoring, all image features inherit from this base class
-
get_weight
()[source] gets weight of particular feature
Returns: weight of the feature Return type: float
-
Katna.image_features.edge_feature¶
-
class
Katna.image_features.edge_feature.
EdgeFeature
(weight=0.0)[source] Bases:
Katna.image_features.feature.Feature
Class for getting edge detector Feature, Constructor Parameters:- feature weight
Internal Parameters:-
min_val_threshold : min edge threshold
max_val_threshold : max edge threshold
ksize: size of Sobel kernel used for finding image gradients
-
get_feature_map
(image)[source] Public function for getting Feature map image from edges detection
Parameters: image (numpy array) – input image Returns: single channel opencv numpy image with feature map from edge detection Return type: numpy array
-
Katna.image_features.saliency_feature¶
-
class
Katna.image_features.saliency_feature.
SaliencyFeature
(weight=0.0)[source] Bases:
Katna.image_features.feature.Feature
Class for calculating saliency feature map from Input image
-
get_feature_map
(image)[source] Public function for getting Feature map image from Image saliency detection
Parameters: image (numpy array) – input image Returns: single channel opencv numpy image with feature map from saliency detection Return type: numpy array
-
Katna.image_features.face_feature¶
-
class
Katna.image_features.face_feature.
FaceFeature
(weight=1.0)[source] Bases:
Katna.image_features.feature.Feature
Class for calculating Face detection feature map from input image
Internal Parameters
model_file : Path for downloading model for face detection
prototxt_file : Path for downloading model description prototxt file
confidence : Face detection confidence threshold value
Constructor for this class does following tasks, if not already downloaded , it first downloads face detector model file and prototxt file from public URL ands save it at USER_HOME/.katna directory, or /tmp/.katna directory. After this initializer code initializes internal parameter: min_confidence (for face detection)
-
download_model
()[source] Public function for downloading the network weight from the URL link, to be used for face detection functionality. Troubleshooting tip: If you get FileNotFound error during face detector initialization, initialize the face detector and call this function directly to download the model file from public URL link.
-
download_proto
()[source] Public function for downloading the network weight from the URL link, to be used for face detection functionality. Troubleshooting tip: If you get FileNotFound error during face detector initialization, initialize the face detector and call this function directly to download the model file from public URL link.
-
get_feature_map
(image)[source] Public function for getting Feature map image from Face detection in input Image
Parameters: image (numpy array) – input image Returns: single channel opencv numpy image with feature map from Face detection Return type: numpy array
-