コード例 #1
0
 def _split_normal_img_by_size(self,
                               path: str,
                               row_len,
                               column_len: int,
                               sub_path_func: typing.Callable[[str, int],
                                                              str],
                               replace_exist=True):
     """图片分割"""
     img = cvutil.load_img(path)
     total_height, total_width = img.shape[:2]
     width, height = total_width // column_len, total_height // row_len
     num = 1
     station_str = Path(path).stem.split('_')[0]
     for i in range(0, row_len):
         left_top_height = i * height
         right_bottom_height = (i + 1) * height
         for j in range(0, column_len):
             sub_path = sub_path_func(path=path,
                                      num=num * self.thumbnailDuration)
             if Path(sub_path).exists() and replace_exist:
                 continue
             left_top_width = j * width
             right_bottom_width = (j + 1) * width
             roi = img[left_top_height:right_bottom_height,
                       left_top_width:right_bottom_width]
             roi = cvutil.resize(roi, self.resize_width, self.resize_height)
             cvutil.save_img(sub_path, roi)
             if os.path.getsize(sub_path) < 1024:
                 self.log.info(
                     f'[{self.user_id}:{station_str}] invalid img size DEL {sub_path}'
                 )
                 os.remove(sub_path)
             num += 1
     return width, height
コード例 #2
0
ファイル: test_cvutil.py プロジェクト: weakeng/AfreecaDance
def test_shape():
    path = 'img/0:0:3_0.jpg'

    img = cvutil.load_img(path)
    img = cvutil.gray(img)
    img = img.flatten() / 255
    print(img.shape)
    p = Path(path)
    print(p.stem.split('_')[-1])
    print()
コード例 #3
0
def cv_load(path: str):
    img = cvutil.load_img(path)
    total_height, total_width = img.shape[:2]
    return img, total_width, total_height
コード例 #4
0
ファイル: base_model.py プロジェクト: weakeng/AfreecaDance
 def _prepare_img_by_path(path: str) -> np.array:
     img = cvutil.load_img(path)
     img = cvutil.gray(img)
     # flatten 转为一维
     img = img.flatten() / 255
     return img