Can’t grab frame, what happend?

Anyone can help me to solve it?..

  1. this is work fine. And Cam looks.

import cv2
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 400)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 600)
if cap.isOpened():
    ret, a =
    while ret:
        ret, a =
        cv2.imshow("camera", a)
        if cv2.waitKey(1) & 0xFF == 27:
        if cv2.waitKey(1) != -1:
  1. But, this is not working. And Cam not looks with the following error. What’s wrong? Thanks.

(error msg)

  1. OnReadSample() is called with error status: -1072873822
  2. async ReadSample() call is failed with error status: -1072873822
  3. can’t grab frame. Error: -1072873822
  4. SourceReaderCB::~SourceReaderCB terminating async callback


import cv2
import numpy as np
import dlib
import sys

scaler = 0.3
predictor_path = 'shape_predictor_68_face_landmarks.dat'
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
#cap = cv2.VideoCapture('video.mp4') # this is work fine
cap = cv2.VideoCapture(0) # but .....this is not working

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 400)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 600)

if not cap.isOpened():
    raise IOError("Cannot open webcam")
while cap.isOpened():
    ret, img =
    if not ret:

    img = cv2.resize(img , (int(img.shape[1]* scaler), int(img.shape[0]*scaler))) 
    ori = img.copy() 
    faces = detector(img)
    if len(faces)>0:
        face = faces[0]
        dlib_shape = predictor(img, face)
        shape_2d = np.array([[p.x, p.y] for p in])

        top_left = np.min(shape_2d, axis=0)
        bottom_rigth = np.max(shape_2d, axis=0)

        img = cv2.rectangle(img, pt1 = (face.left(),, pt2 =(face.right(), face.bottom()), color= (255,255,255) ,thickness= 2)

        for s in shape_2d:
  , center = tuple(s), radius =1 , color=(255,255,255) ,thickness= 2)

        cv2.imshow('result', img)
        if cv2.waitKey(10) & 0xFF == ord('q'):

please be more concise about “cant grab frame”. what exactly happens ?

this is usually the result of some previous error. some exception happened, and the (MSMF) capture terminates.

it’s also “not working” as a problem description"
please append the complete python stacktrace to your question !