程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python3 讀取本地、網絡攝像頭流

編輯:Python

1. Python3 讀取本地攝像頭流

import cv2
if __name__ == "__main__":
cap = cv2.VideoCapture(0)
while 1 > 0:
ret, frameNow = cap.read()
if ret:
cv2.resize(frameNow, (0, 0), fx=0.5, fy=0.5)
img = cv2.resize(frameNow, dsize=(400, 400))
cv2.imshow("CAMERA", img)
if ord('q') == cv2.waitKey(10):
cap.release()
cv2.destroyAllWindows()
exit(0)

2. Python3 讀取網絡攝像頭流

import cv2
if __name__ == "__main__":
# rtmp 拉流,需要同一個局域網 rtsp://用戶名:密碼@IP/h265/ch1/main/av_stream
url = 'rtsp://admin:[email protected]/h265/ch1/main/av_stream'
cap = cv2.VideoCapture(url)
while 1 > 0:
ret, frameNow = cap.read()
if ret:
cv2.resize(frameNow, (0, 0), fx=0.5, fy=0.5)
img = cv2.resize(frameNow, dsize=(400, 400))
cv2.imshow("CAMERA", img)
if ord('q') == cv2.waitKey(10):
cap.release()
cv2.destroyAllWindows()
exit(0)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved