Why is the null type expected error occurs if VideoCapture('vtest.avi') is replaced by VideoCapture(0) in BackgroundSubtractorMOG2 tutorial?

asked 2017-01-25 03:33:02 -0600

updated 2017-01-25 03:41:05 -0600

berak gravatar image
import numpy as np
import cv2

cap = cv2.VideoCapture(0)

fgbg = cv2.createBackgroundSubtractorMOG2()

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()
edit retag flag offensive close merge delete

Comments

  • which opencv version is it, exactly ? (cv2.__version__)
  • please add the stacktrace to your question.
  • as always, you must checkcap.isOpened() , and also the ret value.
berak gravatar imageberak ( 2017-01-25 03:42:13 -0600 )edit

@Mareena, welcome on board! For your next question, please use short title and post your question in the text area. A small tour on FAQ also is useful.

pklab gravatar imagepklab ( 2017-01-25 05:36:54 -0600 )edit