You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
642 B

6 years ago
  1. from urllib.request import urlopen, Request
  2. from urllib.parse import urlencode
  3. import cv2
  4. import json
  5. AI_IP = '192.168.2.252'
  6. cam = cv.VideoCapture('http://10.42.0.151:8080/?action=stream')
  7. while True:
  8. ret, img = cam.read()
  9. img = cv2.resize(img, (1280, 960))
  10. url = 'https://{}:5001/ai'.format(AI_IP)
  11. _, buffer = cv2.imencode('.jpg', img)
  12. post_fields = {'img': base64.b64encode(buffer).decode('ascii'), "type": "damage"}
  13. request = Request(url, urlencode(post_fields).encode())
  14. output_dict = json.loads(json.loads(urlopen(request, context=context).read()))
  15. cv2.imshow('Image', img)
  16. cv2.waitKey(0)