opencv-python调用笔记本摄像头

很简单,直接上代码。方便以后需要的时候难找。

# -*- coding: utf-8 -*
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
fgbg = cv2.createBackgroundSubtractorMOG()
while(1):
    ret, frame = cap.read()
    fgmask = fgbg.apply(frame)
    cv2.imshow('frame',fgmask)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break
cap.release()
cv2.destroyAllWindows()

你可能感兴趣的:(图像处理,python)