herrDeng網內搜尋

自訂搜尋

Ads

2022年5月16日 星期一

練習requests & 用opencv VideoCapture看網路圖

  1. print('練習requests & 用opencv VideoCapture看網路圖')
  2.  
  3. !pip install opencv-python
  4.  
  5. import requests
  6. r=requests.get('https://stats.moe.gov.tw/files/detail/109/109_student.csv')
  7.  
  8. s=r.text
  9. print(s[0:s.find('\r\n')])
  10.  
  11.  
  12. s=r.text
  13. s0=s[s.find('科技大學'):]
  14. i=s0.rfind('科技大學')
  15. i
  16.  
  17.  
  18. s.count('科技大學')
  19.  
  20. ?str.find
  21.  
  22. t=s0[0:s0.find('\r\n',i)]
  23. t
  24.  
  25. #下面捉網路狗狗圖檔
  26. url='https://random.dog/woof.json'
  27. r2=requests.get(url)
  28. data=r2.json()
  29. data
  30.  
  31. import cv2
  32.  
  33. cap=cv2.VideoCapture(data['url'])
  34. _,m=cap.read()
  35. cv2.imshow(data['url'],m)
  36. cv2.waitKey(0)
  37. cv2.destroyAllWindows()
  38.  
  39. #如果要取得隨機柴犬,請試
  40. url='https://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true'
  41. r3=requests.get(url)
  42. data=r3.json()
  43. data
  44.  
如果是mp4要怎麼改
  1. cap=cv2.VideoCapture(data['url'])
  2. print(data['url'])
  3. while True:
  4. ret,m=cap.read()
  5. if ret==False:
  6. break
  7. size=m.shape
  8. m=cv2.resize(m, (608, int(608/size[1]*size[0])))
  9. cv2.imshow(data['url'],m)
  10. if data['url'].find('.mp4')==-1 :
  11. cv2.waitKey(0)
  12. else:
  13. cv2.waitKey(32)
  14. cv2.destroyAllWindows()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章