- print('練習requests & 用opencv VideoCapture看網路圖')
-
- !pip install opencv-python
-
- import requests
- r=requests.get('https://stats.moe.gov.tw/files/detail/109/109_student.csv')
-
- s=r.text
- print(s[0:s.find('\r\n')])
-
-
- s=r.text
- s0=s[s.find('科技大學'):]
- i=s0.rfind('科技大學')
- i
-
-
- s.count('科技大學')
-
- ?str.find
-
- t=s0[0:s0.find('\r\n',i)]
- t
-
- #下面捉網路狗狗圖檔
- url='https://random.dog/woof.json'
- r2=requests.get(url)
- data=r2.json()
- data
-
- import cv2
-
- cap=cv2.VideoCapture(data['url'])
- _,m=cap.read()
- cv2.imshow(data['url'],m)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-
- #如果要取得隨機柴犬,請試
- url='https://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true'
- r3=requests.get(url)
- data=r3.json()
- data
-
如果是mp4要怎麼改
- cap=cv2.VideoCapture(data['url'])
- print(data['url'])
- while True:
- ret,m=cap.read()
- if ret==False:
- break
- size=m.shape
- m=cv2.resize(m, (608, int(608/size[1]*size[0])))
- cv2.imshow(data['url'],m)
- if data['url'].find('.mp4')==-1 :
- cv2.waitKey(0)
- else:
- cv2.waitKey(32)
- cv2.destroyAllWindows()
沒有留言:
張貼留言