Exemplo n.º 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
Exemplo n.º 2
0
def cv_cut(img, path: str, num: int, left_top_width, left_top_height,
           right_bottom_width, right_bottom_height: int):
    roi = img[left_top_height:right_bottom_height,
              left_top_width:right_bottom_width]
    a = sub_path(path, num)
    cvutil.save_img(a, roi)
    if os.path.getsize(a) < 1024 * 3:
        os.remove(a)