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)