enter.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import cv2
  2. import numpy as np
  3. from utility import *
  4. from argument import *
  5. from core import HuiMvOcr
  6. from time import time
  7. def main(args: "ArgType"):
  8. image_file_list = get_image_file_list(args.image_dir)
  9. engine = HuiMvOcr(args)
  10. # warm up 10 times
  11. if args.warmup:
  12. img = np.random.uniform(0, 255, [640, 640, 3]).astype(np.uint8)
  13. for i in range(10):
  14. engine.ocr_one(img)
  15. # single
  16. print("single start")
  17. total_time, res = 0, []
  18. for image_file in image_file_list:
  19. img, flag_gif = check_and_read(image_file)
  20. if not flag_gif:
  21. img = cv2.imread(image_file) # noqa
  22. st = time()
  23. rec_res = engine.ocr_one(img, cls=True, use_space=False)
  24. elapse = time() - st
  25. total_time += elapse
  26. res.append(rec_res)
  27. print(f"single total time: {total_time}")
  28. for i in range(len(res)):
  29. print(f"file: {image_file_list[i]}")
  30. print("res:", res[i])
  31. # multi
  32. images = [cv2.imread(file) for file in image_file_list] # noqa
  33. print("\n\nmulti start")
  34. st = time()
  35. res = engine.ocr_multi(images, cls=True, use_space=False)
  36. print(f"multi total time {time() - st}")
  37. for i in range(len(res)):
  38. print(f"file: {image_file_list[i]}")
  39. print("res:", res[i])
  40. if __name__ == "__main__":
  41. main(Args())