Anyone can help me to solve it?..
- 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 = cap.read()
while ret:
ret, a = cap.read()
cv2.imshow("camera", a)
if cv2.waitKey(1) & 0xFF == 27:
break
if cv2.waitKey(1) != -1:
cv2.imwrite('cap.png',a)
cap.release()
cv2.destroyAllWindows()
- But, this is not working. And Cam not looks with the following error. What’s wrong? Thanks.
(error msg)
- OnReadSample() is called with error status: -1072873822
- async ReadSample() call is failed with error status: -1072873822
- can’t grab frame. Error: -1072873822
- SourceReaderCB::~SourceReaderCB terminating async callback
(source)
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 = cap.read()
if not ret:
break
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 dlib_shape.parts()])
top_left = np.min(shape_2d, axis=0)
bottom_rigth = np.max(shape_2d, axis=0)
img = cv2.rectangle(img, pt1 = (face.left(), face.top()), pt2 =(face.right(), face.bottom()), color= (255,255,255) ,thickness= 2)
for s in shape_2d:
cv2.circle(img, center = tuple(s), radius =1 , color=(255,255,255) ,thickness= 2)
cv2.imshow('result', img)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()