From 5d6e8e9e95cc80bc8a5a9a57d59ce73c5f96c166 Mon Sep 17 00:00:00 2001 From: Zhiying Li <zhiyingli@g.ucla.edu> Date: Tue, 12 Oct 2021 03:59:52 +0000 Subject: [PATCH] Update Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread.py --- .../PyTorch_with_ESPCAM/imageTread.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread.py diff --git a/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread.py b/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread.py new file mode 100644 index 0000000..a93b444 --- /dev/null +++ b/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread.py @@ -0,0 +1,33 @@ +import cv2 +from urllib.request import urlopen, Request +import numpy as np + +def nothing(x): + pass + + + +#change the IP address below according to the +#IP shown in the Serial monitor of Arduino code +url='http://192.168.1.107/cam-lo.jpg' +# url='http://192.168.1.107/cam-hi.jpg' +# url='http://192.168.1.107/cam-mid.jpg' + + +cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE) + + +while True: + header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36."} + req = Request(url, headers=header) + img_resp = urlopen(req, timeout=60) + imgnp=np.array(bytearray(img_resp.read()),dtype=np.uint8) + frame=cv2.imdecode(imgnp,-1) + + + cv2.imshow("live transmission", frame) + key=cv2.waitKey(5) + if key==ord('q'): + break + +cv2.destroyAllWindows() -- GitLab