yolo_test_handler.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2022/2/28 15:06
  3. # @Author : MaochengHu
  4. # @Email : wojiaohumaocheng@gmail.com
  5. # @File : yolo_test_handler.py
  6. # @Project : server_develop
  7. import sys
  8. import os
  9. root_src = "../../src"
  10. def import_env(names):
  11. for name in names:
  12. sys.path.append(os.path.join(os.getcwd(), name))
  13. append_path = ["../../src/server_utils", "../../src/", "../../src/model_structure",
  14. "../../src/model_structure/yolov5_structure/yolov5-master"]
  15. import_env(append_path)
  16. from server_utils.image_convert import path2base64
  17. from object_detector_handler import ObjectDetectionHandler
  18. def main():
  19. test_source = "../test_images/test1.jpg"
  20. base64str = path2base64(test_source)
  21. context = None
  22. # , "pd_xywhn", "pd_xyxy", "pd_xyxyn", "tolist", "crop_np", "crop_base64",
  23. # "detail_time_info", "render_base64"
  24. output_methods = ["pd_xywh_json"]
  25. obh = ObjectDetectionHandler()
  26. data = {"data": base64str, "output_methods": str(output_methods).encode(), "base64_bool": str(True).encode()}
  27. result = obh.handle([data], context)
  28. print(result)
  29. if __name__ == "__main__":
  30. main()