cvtools.utils package

Module contents

cvtools.utils.get_files_list(root, file_type=None, basename=False)[源代码]

file_type is a str or list.

cvtools.utils.get_images_list(root_dir)[源代码]
cvtools.utils.split_list(data_list, test_size=0.1)[源代码]
cvtools.utils.split_dict(data_dict, test_size=0.1)[源代码]
cvtools.utils.split_data(root, files, dst, test_size=0.1)[源代码]
cvtools.utils.replace_filename_space(src_root, dst_root)[源代码]
cvtools.utils.check_rept(file)[源代码]
cvtools.utils.makedirs(path)[源代码]

对os.makedirs进行扩展

从路径中创建文件夹,可创建多层。如果仅是文件名,则无须创建,返回False; 如果是已存在文件或路径,则无须创建,返回False

参数:path -- 路径,可包含文件名。纯路径最后一个字符需要是os.sep
cvtools.utils.sample_label_from_images(images_src, labels_src, dst)[源代码]
cvtools.utils.folder_name_replace(path, list_replace)[源代码]
cvtools.utils.files_name_replace(path, file_type=None, folder=False, list_replace=None)[源代码]
cvtools.utils.folder_name_replace(path, list_replace)[源代码]
cvtools.utils.files_name_replace(path, file_type=None, folder=False, list_replace=None)[源代码]
cvtools.utils.check_file_exist(filename, msg_tmpl='file "{}" does not exist')[源代码]
cvtools.utils.isfile_casesensitive(path)[源代码]
cvtools.utils.is_image_file(filename)[源代码]
cvtools.utils.find_in_path(name, path)[源代码]

Find a file in a search path

cvtools.utils.splitpath(path)[源代码]
cvtools.utils.imread(img_or_path, flag='color')[源代码]

Read an image.

参数:
  • img_or_path (ndarray or str) -- Either a numpy array or image path. If it is a numpy array (loaded image), then it will be returned as is.
  • flag (str) -- Flags specifying the color type of a loaded image, candidates are color, grayscale and unchanged.
返回:

Loaded image array.

返回类型:

ndarray

cvtools.utils.imwrite(img, file_path, params=None, auto_mkdir=True)[源代码]

Write image to file

参数:
  • img (ndarray) -- Image array to be written.
  • file_path (str) -- Image file path.
  • params (None or list) -- Same as opencv's imwrite() interface.
  • auto_mkdir (bool) -- If the parent folder of file_path does not exist, whether to create it automatically.
返回:

Successful or not.

返回类型:

bool

cvtools.utils.draw_boxes_texts(img, boxes, texts=None, colors=None, line_width=1, draw_start=False, box_format='x1y1x2y2')[源代码]

Draw bboxes on an image.

参数:
  • img (str or ndarray) -- The image to be displayed.
  • boxes (list or ndarray) -- A list of ndarray of shape (k, 4).
  • texts (list) -- A list of shape (k).
  • colors (list[tuple or Color]) -- A list of colors.
  • line_width (int) -- Thickness of lines.
  • draw_start (bool) -- Draw a dot at the first vertex of the box.
  • box_format (str) -- x1y1x2y2(default), x1y1wh, xywh, xywha, polygon
cvtools.utils.draw_class_distribution(y, save_name='class_distribution.png')[源代码]

绘制饼图,其中y是标签列表

cvtools.utils.draw_hist(data, bins=10, x_label='区间', y_label='频数/频率', title='频数/频率分布直方图', show=True, save_name='hist.png', density=True)[源代码]

绘制直方图 data: 必选参数,绘图数据 bins: 直方图的长条形数目,可选项,默认为10

cvtools.utils.x1y1wh_to_x1y1x2y2(xywh)[源代码]

Convert [x1 y1 w h] box format to [x1 y1 x2 y2] format. supported type: list, type and np.ndarray

cvtools.utils.x1y1x2y2_to_x1y1wh(xyxy)[源代码]

Convert [x1 y1 x2 y2] box format to [x1 y1 w h] format.

cvtools.utils.xywh_to_x1y1x2y2(xywh)[源代码]

Convert [x y w h] box format to [x1 y1 x2 y2] format.

cvtools.utils.x1y1x2y2_to_xywh(x1y1x2y2)[源代码]

Convert [x1 y1 x2 y2] box format to [x y w h] format.

cvtools.utils.x1y1wh_to_xywh(x1y1wh)[源代码]

Convert [x1 y1 w h] box format to [x y w h] format. supported type: list, type and np.ndarray

cvtools.utils.rotate_rect(rect, center, angle)[源代码]

一个数学问题:2x2矩阵(坐标)与旋转矩阵相乘. 在笛卡尔坐标系中,angle>0, 逆时针旋转; angle<0, 顺时针旋转

参数:
  • rect -- x1y1x2y2形式矩形
  • center -- 旋转中心点
  • angle -- 旋转角度,范围在(-180, 180)
返回:

x1y1x2y2x3y3x4y4 format box

cvtools.utils.xywha_to_x1y1x2y2x3y3x4y4(xywha)[源代码]

用旋转的思路做变换是最通用和最简单的

警告:目前多维一起操作还有些问题!

参数:xywha -- (5,)一维list或(K, 5)多维array
class cvtools.utils.Timer[源代码]

基类:object

A simple timer.

reset()[源代码]
tic()[源代码]
toc(average=True)[源代码]
cvtools.utils.get_time_str(form='%Y%m%d_%H%M%S')[源代码]

for example form='%Y%m%d_%H%M%S_%f'

cvtools.utils.read_arcsoft_txt_format(file)[源代码]
cvtools.utils.read_jiang_txt(file)[源代码]
cvtools.utils.read_yuncong_detect_file(file, num_class)[源代码]
cvtools.utils.bbox_overlaps(bboxes1, bboxes2, mode='iou')[源代码]

Calculate the ious between each bbox of bboxes1 and bboxes2.

参数:
  • bboxes1 (ndarray) -- shape (n, 4)
  • bboxes2 (ndarray) -- shape (k, 4)
  • mode (str) -- iou (intersection over union) or iof (intersection over foreground)
返回:

shape (n, k)

返回类型:

ious(ndarray)

cvtools.utils.is_str(x)[源代码]

Whether the input is an string instance.

cvtools.utils.iter_cast(inputs, dst_type, return_type=None)[源代码]

Cast elements of an iterable object into some type.

参数:
  • inputs (Iterable) -- The input object.
  • dst_type (type) -- Destination type.
  • return_type (type, optional) -- If specified, the output object will be converted to this type, otherwise an iterator.
返回:

The converted object.

返回类型:

iterator or specified type

cvtools.utils.list_cast(inputs, dst_type)[源代码]

Cast elements of an iterable object into a list of some type.

A partial method of iter_cast().

cvtools.utils.tuple_cast(inputs, dst_type)[源代码]

Cast elements of an iterable object into a tuple of some type.

A partial method of iter_cast().

cvtools.utils.is_seq_of(seq, expected_type, seq_type=None)[源代码]

Check whether it is a sequence of some type.

参数:
  • seq (Sequence) -- The sequence to be checked.
  • expected_type (type) -- Expected type of sequence items.
  • seq_type (type, optional) -- Expected sequence type.
返回:

Whether the sequence is valid.

返回类型:

bool

cvtools.utils.is_list_of(seq, expected_type)[源代码]

Check whether it is a list of some type.

A partial method of is_seq_of().

cvtools.utils.is_tuple_of(seq, expected_type)[源代码]

Check whether it is a tuple of some type.

A partial method of is_seq_of().

cvtools.utils.slice_list(in_list, lens)[源代码]

Slice a list into several sub lists by a list of given length.

参数:
  • in_list (list) -- The list to be sliced.
  • lens (int or list) -- The expected length of each out list.
返回:

A list of sliced list.

返回类型:

list

cvtools.utils.concat_list(in_list)[源代码]

Concatenate a list of list into a single list.

参数:in_list (list) -- The list of list to be merged.
返回:The concatenated flat list.
返回类型:list
cvtools.utils.is_array_like(obj)[源代码]
cvtools.utils.get_logger(level=20, name=None)[源代码]
cvtools.utils.logger_file_handler(logger, filename=None, mode='w', level=20)[源代码]