draw_html.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import argparse
  16. def str2bool(v):
  17. return v.lower() in ("true", "t", "1")
  18. def init_args():
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument("--image_dir", type=str, default="")
  21. parser.add_argument("--save_html_path", type=str, default="./default.html")
  22. parser.add_argument("--width", type=int, default=640)
  23. return parser
  24. def parse_args():
  25. parser = init_args()
  26. return parser.parse_args()
  27. def draw_debug_img(args):
  28. html_path = args.save_html_path
  29. err_cnt = 0
  30. with open(html_path, 'w') as html:
  31. html.write('<html>\n<body>\n')
  32. html.write('<table border="1">\n')
  33. html.write(
  34. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
  35. )
  36. image_list = []
  37. path = args.image_dir
  38. for i, filename in enumerate(sorted(os.listdir(path))):
  39. if filename.endswith("txt"): continue
  40. # The image path
  41. base = "{}/{}".format(path, filename)
  42. html.write("<tr>\n")
  43. html.write(f'<td> {filename}\n GT')
  44. html.write(f'<td>GT\n<img src="{base}" width={args.width}></td>')
  45. html.write("</tr>\n")
  46. html.write('<style>\n')
  47. html.write('span {\n')
  48. html.write(' color: red;\n')
  49. html.write('}\n')
  50. html.write('</style>\n')
  51. html.write('</table>\n')
  52. html.write('</html>\n</body>\n')
  53. print(f"The html file saved in {html_path}")
  54. return
  55. if __name__ == "__main__":
  56. args = parse_args()
  57. draw_debug_img(args)