python opencv3 獲取攝像頭視頻


 git:https://github.com/linyi0604/Computer-Vision

 

 

 1 # coding:utf8
 2 
 3 import cv2  4 
 5 
 6 """
 7 捕獲攝像頭10s的視頻信息 寫入一個avi文件  8 """
 9 
10 cameraCapture = cv2.VideoCapture(0)     # 傳入0代表0號攝像頭
11 fps = 30
12 size = ( 13  int(cameraCapture.get(cv2.CAP_PROP_FRAME_WIDTH)), 14  int(cameraCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)) 15 ) 16 
17 videoWriter = cv2.VideoWriter( 18     "outputVid.avi", 19     cv2.VideoWriter_fourcc("I", "4", "2", "0"), 20  fps, 21  size 22 ) 23 
24 success, frame = cameraCapture.read() 25 numFramesRemaining = 10 * fps - 1
26 while success and numFramesRemaining: 27  videoWriter.write(frame) 28     success, frame = cameraCapture.read() 29     numFramesRemaining -= 1
30 
31 cameraCapture.release() 32 
33 
34 """
35 如果使用一組攝像頭或多個攝像頭 36 用grab和retrieve方法代替 37 
38 success0 = cameraCapture.grab() 39 success1 = cameraCapture.grab() 40 if success0 and success1: 41  frame0 = cameraCapture0.retrieve() 42  frame1 = cameraCapture1.retrieve() 43     
44     
45 """

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM