draw_html.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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"):
  40. continue
  41. # The image path
  42. base = "{}/{}".format(path, filename)
  43. html.write("<tr>\n")
  44. html.write(f"<td> {filename}\n GT")
  45. html.write(f'<td>GT\n<img src="{base}" width={args.width}></td>')
  46. html.write("</tr>\n")
  47. html.write("<style>\n")
  48. html.write("span {\n")
  49. html.write(" color: red;\n")
  50. html.write("}\n")
  51. html.write("</style>\n")
  52. html.write("</table>\n")
  53. html.write("</html>\n</body>\n")
  54. print(f"The html file saved in {html_path}")
  55. return
  56. if __name__ == "__main__":
  57. args = parse_args()
  58. draw_debug_img(args)