P14 3-6
1 读取本地视频
1.1 绝对路径 4种方式
cap=cv2.VideoCapture("E:/Python/opencv-master源码/opencv-master/opencv/轮廓/video.mp4")
1.2 相对路径 4种方式
1.3 读取本地视频
import cv2
from cv2 import WINDOW_NORMAL
import numpy as np
cap=cv2.VideoCapture("E:/Python/opencv-master源码/opencv-master/opencv/轮廓/video.mp4")
while True:
ret,frame=cap.read()
cv2.imshow('video',frame)
key=cv2.waitKey(20)
if(key == 113):
break
cv2.destroyWindow()

2 视频基本信息
if(cap.read()):
w=cap.get(CAP_PROP_FRAME_WIDTH)
h=cap.get(CAP_PROP_FRAME_HEIGHT)
fps=cap.get(CAP_PROP_FPS)
count=cap.get(CAP_PROP_FRAME_COUNT)
print('视频中图像宽度:%d' %(w))
print('视频中图像高度:%d' %(w))
print('视频的帧率:%d' %(fps))
print('视频总帧数:%d' %(count))

3 调用摄像头
import cv2
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
vw = cv2.VideoWriter('./out.mp4', fourcc, 25, (1280, 720))
cv2.namedWindow('video', cv2.WINDOW_NORMAL)
cv2.resizeWindow('video', 640, 360)
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
cv2.imshow('video', frame)
cv2.resizeWindow('video', 640, 360)
vw.write(frame)
key = cv2.waitKey(1)
if(key & 0xFF == ord('q')):
break
else:
break
cap.release()
vw.release()
cv2.destroyAllWindows()
