MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / __call__

Method __call__

tools/infer_e2e.py:220–402  ·  view source on GitHub ↗

img_path: str, optional, default=None Path to the directory containing images or the image filename. save_dir: str, optional, default='e2e_results/' Directory to save prediction and visualization results. Defaults to a subfolder in img_path. is_visual

(self,
                 img_path=None,
                 save_dir='e2e_results/',
                 is_visualize=False,
                 img_numpy=None,
                 rec_batch_num=6,
                 crop_infer=False,
                 return_mask=False,
                 **kwargs)

Source from the content-addressed store, hash-verified

218 }
219
220 def __call__(self,
221 img_path=None,
222 save_dir='e2e_results/',
223 is_visualize=False,
224 img_numpy=None,
225 rec_batch_num=6,
226 crop_infer=False,
227 return_mask=False,
228 **kwargs):
229 """
230 img_path: str, optional, default=None
231 Path to the directory containing images or the image filename.
232 save_dir: str, optional, default='e2e_results/'
233 Directory to save prediction and visualization results. Defaults to a subfolder in img_path.
234 is_visualize: bool, optional, default=False
235 Visualize the results.
236 img_numpy: numpy or list[numpy], optional, default=None
237 numpy of an image or List of numpy arrays representing images.
238 rec_batch_num: int, optional, default=6
239 Batch size for text recognition.
240 crop_infer: bool, optional, default=False
241 Whether to use crop inference.
242 """
243
244 if img_numpy is None and img_path is None:
245 raise ValueError('img_path and img_numpy cannot be both None.')
246 if img_numpy is not None:
247 if not isinstance(img_numpy, list):
248 img_numpy = [img_numpy]
249 results = []
250 time_dicts = []
251 for index, img in enumerate(img_numpy):
252 ori_img = img.copy()
253 if return_mask:
254 dt_boxes, rec_res, time_dict, mask = self.infer_single_image(
255 img_numpy=img,
256 ori_img=ori_img,
257 crop_infer=crop_infer,
258 rec_batch_num=rec_batch_num,
259 return_mask=return_mask,
260 **kwargs)
261 else:
262 dt_boxes, rec_res, time_dict = self.infer_single_image(
263 img_numpy=img,
264 ori_img=ori_img,
265 crop_infer=crop_infer,
266 rec_batch_num=rec_batch_num,
267 **kwargs)
268 if dt_boxes is None:
269 results.append([])
270 time_dicts.append({})
271 continue
272 res = [{
273 'transcription': rec_res[i][0],
274 'points': np.array(dt_boxes[i]).tolist(),
275 'score': rec_res[i][1],
276 } for i in range(len(dt_boxes))]
277 results.append(res)

Callers

nothing calls this directly

Calls 5

infer_single_imageMethod · 0.95
get_image_file_listFunction · 0.90
check_and_readFunction · 0.90
draw_ocr_box_txtFunction · 0.90
check_and_download_fontFunction · 0.85

Tested by

no test coverage detected