test.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import asyncio
  2. from logger import logger
  3. from config import Config
  4. from uploadData import upload
  5. from parser import parse_multipart
  6. from parser import parser_json_data
  7. from byteimg import byte2pil, pil2byte, draw
  8. conf = Config.get("prod")
  9. url = conf["url"]
  10. channel = conf["channel"]
  11. classIndex = conf["classIndex"]
  12. nvr = conf["nvr"]
  13. print(url)
  14. async def local_test():
  15. with open("../assert/isapi_data/tfs_0.txt", "r") as f:
  16. multipart_data = eval(f.read())
  17. boundary = b'---------------------------7e13971310878'
  18. result = parse_multipart(multipart_data, boundary)
  19. car_infos, image_contents = parser_json_data(result)
  20. if len(car_infos) != 0:
  21. # with open(f"assert/{index}-tfx.txt", "wb") as f:
  22. # f.write(multipart_data)
  23. logger.info(car_infos)
  24. for info, image_content in zip(car_infos, image_contents):
  25. try:
  26. videoTime = info["dateTime"]
  27. speed = info["VehicleInfo"]["vehicleSpeed"]
  28. plate = info["PlateInfo"]["plate"]
  29. filename = None
  30. imagedata = None
  31. filename = image_content["filename"]
  32. if filename != "detectionPicture.jpg":
  33. continue
  34. imagedata = image_content["content"]
  35. if imagedata is not None:
  36. # img = byte2pil(imagedata)
  37. # text = f"{plate} : {speed} km/h"
  38. # draw(img, text, (100, 100))
  39. # byte_data = pil2byte(img)
  40. # img.show()
  41. res = await upload(url, channel, classIndex, nvr, videoTime, filename, imagedata, plate, speed)
  42. logger.info(res)
  43. except Exception as error:
  44. logger.info(error)
  45. return {"msg": "sucess"}
  46. if __name__ == "__main__":
  47. asyncio.run(local_test())