cvtools.utils package¶
Submodules¶
Module contents¶
-
cvtools.utils.
get_files_list
(root, file_type=None, basename=False)[源代码]¶ file_type is a str or list.
-
cvtools.utils.
makedirs
(path)[源代码]¶ 对os.makedirs进行扩展
从路径中创建文件夹,可创建多层。如果仅是文件名,则无须创建,返回False; 如果是已存在文件或路径,则无须创建,返回False
参数: path -- 路径,可包含文件名。纯路径最后一个字符需要是os.sep
-
cvtools.utils.
folder_name_replace
(path, list_replace)[源代码]
-
cvtools.utils.
files_name_replace
(path, file_type=None, folder=False, list_replace=None)[源代码]
-
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_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.
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
-
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.
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