启动摄像头驱动
虚拟机Linux如何使用笔记本电脑的前置摄像头
vmware 下ubuntu 虚拟机下使用摄像头
摄像头
cap = cv2.ViedoCapture(0)
while True:
rey,frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',frame)
cv2.imshow('gray',gray)
cap.release()
cv2.destroyAllWindows()
视频保存
fourcc = cv2.VideoWrite_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc,20.0,(640,480))
while True:
ret,frame = cap.read()
out.write(frame)
out.release()
综合
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWrite_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc,20.0,(640,480))
while True:
ret,frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
out.write(frame)
cv2.imshow('gray',frame)
cv2.imshow('gray',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()