调用函数,处理输入图像,并返回识别结果。 Args: img_path (str, optional): 图像文件的路径。默认为 None。 img_numpy_list (list, optional): 包含多个图像 numpy 数组的列表。默认为 None。 img_numpy (numpy.ndarray, optional): 单个图像的 numpy 数组。默认为 None。 batch_num (int, optional): 每次处理的图像数量。默认
(self,
img_path=None,
img_numpy_list=None,
img_numpy=None,
batch_num=1)
| 329 | return self.onnx_rec_engine.run(images) |
| 330 | |
| 331 | def __call__(self, |
| 332 | img_path=None, |
| 333 | img_numpy_list=None, |
| 334 | img_numpy=None, |
| 335 | batch_num=1): |
| 336 | """ |
| 337 | 调用函数,处理输入图像,并返回识别结果。 |
| 338 | |
| 339 | Args: |
| 340 | img_path (str, optional): 图像文件的路径。默认为 None。 |
| 341 | img_numpy_list (list, optional): 包含多个图像 numpy 数组的列表。默认为 None。 |
| 342 | img_numpy (numpy.ndarray, optional): 单个图像的 numpy 数组。默认为 None。 |
| 343 | batch_num (int, optional): 每次处理的图像数量。默认为 1。 |
| 344 | |
| 345 | Returns: |
| 346 | list: 包含识别结果的列表,每个元素为一个字典,包含文件路径(如果有的话)、文本、分数和延迟时间。 |
| 347 | |
| 348 | Raises: |
| 349 | Exception: 如果没有提供图像路径或 numpy 数组,则引发异常。 |
| 350 | """ |
| 351 | |
| 352 | if img_numpy is not None: |
| 353 | img_numpy_list = [img_numpy] |
| 354 | num_img = 1 |
| 355 | elif img_path is not None: |
| 356 | img_path = get_image_file_list(img_path) |
| 357 | num_img = len(img_path) |
| 358 | elif img_numpy_list is not None: |
| 359 | num_img = len(img_numpy_list) |
| 360 | else: |
| 361 | raise Exception('No input image path or numpy array.') |
| 362 | results = [] |
| 363 | for start_idx in range(0, num_img, batch_num): |
| 364 | batch_data = [] |
| 365 | batch_others = [] |
| 366 | batch_file_names = [] |
| 367 | |
| 368 | max_width, max_height = 0, 0 |
| 369 | # Prepare batch data |
| 370 | for img_idx in range(start_idx, min(start_idx + batch_num, |
| 371 | num_img)): |
| 372 | if img_numpy_list is not None: |
| 373 | img = img_numpy_list[img_idx] |
| 374 | data = {'image': img} |
| 375 | elif img_path is not None: |
| 376 | file_name = img_path[img_idx] |
| 377 | with open(file_name, 'rb') as f: |
| 378 | img = f.read() |
| 379 | data = {'image': img} |
| 380 | data = self.transform(data, self.ops[:1]) |
| 381 | batch_file_names.append(file_name) |
| 382 | batch = self.transform(data, self.ops[1:]) |
| 383 | others = None |
| 384 | if self.cfg['Architecture']['algorithm'] in [ |
| 385 | 'SAR', 'RobustScanner' |
| 386 | ]: |
| 387 | valid_ratio = np.expand_dims(batch[-1], axis=0) |
| 388 | batch_others.append(valid_ratio) |
nothing calls this directly
no test coverage detected