Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import os
  17. import sys
  18. sys.path.insert(
  19. 0,
  20. os.path.abspath(
  21. os.path.join(
  22. os.path.dirname(
  23. os.path.abspath(__file__)),
  24. '../../')))
  25. from deepdoc.vision.seeit import draw_box
  26. from deepdoc.vision import OCR, init_in_out
  27. import argparse
  28. import numpy as np
  29. def main(args):
  30. ocr = OCR()
  31. images, outputs = init_in_out(args)
  32. for i, img in enumerate(images):
  33. bxs = ocr(np.array(img))
  34. bxs = [(line[0], line[1][0]) for line in bxs]
  35. bxs = [{
  36. "text": t,
  37. "bbox": [b[0][0], b[0][1], b[1][0], b[-1][1]],
  38. "type": "ocr",
  39. "score": 1} for b, t in bxs if b[0][0] <= b[1][0] and b[0][1] <= b[-1][1]]
  40. img = draw_box(images[i], bxs, ["ocr"], 1.)
  41. img.save(outputs[i], quality=95)
  42. with open(outputs[i] + ".txt", "w+", encoding='utf-8') as f:
  43. f.write("\n".join([o["text"] for o in bxs]))
  44. if __name__ == "__main__":
  45. parser = argparse.ArgumentParser()
  46. parser.add_argument('--inputs',
  47. help="Directory where to store images or PDFs, or a file path to a single image or PDF",
  48. required=True)
  49. parser.add_argument('--output_dir', help="Directory where to store the output images. Default: './ocr_outputs'",
  50. default="./ocr_outputs")
  51. args = parser.parse_args()
  52. main(args)