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

Python3 reads local and webcam streams

編輯:Python

1. Python3 Read local camera stream

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 Read webcam stream

import cv2
if __name__ == "__main__":
# rtmp Pull flow , Need the same LAN rtsp:// user name : password @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