example.py 931 B

1234567891011121314151617181920212223242526272829
  1. import cv2
  2. from urllib import request
  3. cap = cv2.VideoCapture('http://127.0.0.1:8080/camera')
  4. while True:
  5. ret,frame = cap.read()
  6. cv2.imshow("capture", frame)
  7. key = cv2.waitKey(1)
  8. if key== ord('q'):
  9. break
  10. elif key == ord('w'):
  11. print('send request')
  12. req = request.urlopen('http://127.0.0.1:8080/control?director=w')
  13. res = req.read()
  14. print(res)
  15. elif key == ord('s'):
  16. print('send request')
  17. req = request.urlopen('http://127.0.0.1:8080/control?director=s')
  18. res = req.read()
  19. print(res)
  20. elif key == ord('a'):
  21. print('send request')
  22. req = request.urlopen('http://127.0.0.1:8080/control?director=a')
  23. res = req.read()
  24. print(res)
  25. elif key == ord('d'):
  26. print('send request')
  27. req = request.urlopen('http://127.0.0.1:8080/control?director=d')
  28. res = req.read()
  29. print(res)