Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

79 linhas
2.2KB

  1. from PIL import Image
  2. import numpy as np
  3. import cv2
  4. import base64
  5. import io
  6. import requests
  7. def test():
  8. image_path='test/P0017.png'
  9. image_array=cv2.imread(image_path)
  10. print(image_array.shape)
  11. image_encode=base64.b64encode(image_array).decode('utf-8')
  12. image_bytes=bytes(image_encode,encoding='utf-8')
  13. image_decode=np.frombuffer(base64.decodebytes(image_bytes),dtype=np.uint8)
  14. print(image_decode.shape)
  15. request_url='http://192.168.109.49:5000/'
  16. headers={'content-type':'application/json'}
  17. data={'image':image_encode}
  18. #response=requests.post(request_url,data=data,headers=headers)
  19. response=requests.post(request_url,"POST",files=data)
  20. print(response)
  21. #image=open(image_path,'rb').read()
  22. #image=Image.open(io.BytesIO(image))
  23. #image=image.resize((224,224))
  24. #image=np.asarray(image
  25. def test2():
  26. image_path='test/P0017.png'
  27. image_ori=cv2.imread(image_path)
  28. api = 'http://192.168.109.49:8000/detector'
  29. #img = cv2.imencode('.jpg', img_ori)[-1]
  30. image_encode=base64.b64encode(image_ori).decode('utf-8')
  31. img=bytes(image_encode,encoding='utf-8')
  32. h,w,c=image_ori.shape
  33. files = {'file': img}
  34. files = {'file': img,'name':'P0017',
  35. 'img_width':w,
  36. 'img_height':h,
  37. 'img_chs':c
  38. }
  39. res = requests.request("POST", api, files=files).json()
  40. if res['msg'] == 'success':
  41. bboxes = res['data']['bboxes']
  42. print(bboxes)
  43. #bboxes = np.asarray(bboxes, dtype=np.int32)
  44. def test3():
  45. image_path='test/P0017.png'
  46. image_ori=cv2.imread(image_path)
  47. api = 'http://192.168.109.49:8000/detector'
  48. #img = cv2.imencode('.jpg', img_ori)[-1]
  49. input_ ={
  50. 'img_data':'',
  51. 'img_width':512,
  52. 'img_height':512,
  53. 'img_chs':3
  54. }
  55. with open(image_path,'rb') as f:
  56. input_['img_data']=base64.b64encode(f.read()).decode()
  57. image_encode=base64.b64encode(image_ori).decode('utf-8')
  58. image_bytes=bytes(image_encode,encoding='utf-8')
  59. input_['img_data']=image_bytes:
  60. response=requests.post(api,json=input_)
  61. print(response.text)
  62. if __name__=='__main__':
  63. test2()