(self, img_list)
| 65 | return padding_im |
| 66 | |
| 67 | def __call__(self, img_list): |
| 68 | img_num = len(img_list) |
| 69 | # Calculate the aspect ratio of all text bars |
| 70 | width_list = [] |
| 71 | for img in img_list: |
| 72 | width_list.append(img.shape[1] / float(img.shape[0])) |
| 73 | # Sorting can speed up the recognition process |
| 74 | indices = np.argsort(np.array(width_list)) |
| 75 | rec_res = [['', 0.0]] * img_num |
| 76 | batch_num = self.rec_batch_num |
| 77 | st = time.time() |
| 78 | for beg_img_no in range(0, img_num, batch_num): |
| 79 | end_img_no = min(img_num, beg_img_no + batch_num) |
| 80 | norm_img_batch = [] |
| 81 | imgC, imgH, imgW = self.rec_image_shape[:3] |
| 82 | max_wh_ratio = imgW / imgH |
| 83 | # max_wh_ratio = 0 |
| 84 | for ino in range(beg_img_no, end_img_no): |
| 85 | h, w = img_list[indices[ino]].shape[0:2] |
| 86 | wh_ratio = w * 1.0 / h |
| 87 | max_wh_ratio = max(max_wh_ratio, wh_ratio) |
| 88 | for ino in range(beg_img_no, end_img_no): |
| 89 | if self.rec_algorithm == 'nrtr': |
| 90 | norm_img = transform({'image': img_list[indices[ino]]}, |
| 91 | self.ops)[0] |
| 92 | else: |
| 93 | norm_img = self.resize_norm_img(img_list[indices[ino]], |
| 94 | max_wh_ratio) |
| 95 | norm_img = norm_img[np.newaxis, :] |
| 96 | norm_img_batch.append(norm_img) |
| 97 | norm_img_batch = np.concatenate(norm_img_batch) |
| 98 | norm_img_batch = norm_img_batch.copy() |
| 99 | |
| 100 | preds = self.run(norm_img_batch) |
| 101 | |
| 102 | if len(preds) == 1: |
| 103 | preds = preds[0] |
| 104 | |
| 105 | rec_result = self.postprocess_op({'res': preds}) |
| 106 | for rno in range(len(rec_result)): |
| 107 | rec_res[indices[beg_img_no + rno]] = rec_result[rno] |
| 108 | return rec_res, time.time() - st |
| 109 | |
| 110 | |
| 111 | def main(args): |
nothing calls this directly
no test coverage detected