trouble in using detectmultiple command
trouble in using detectmultiple command
import cv2
import numpy as np
from matplotlib import pyplot as plt
facepath= "c:\cv2\data\haarcascade_frontalface_default.xml"
facecascade=cv2.CascadeClassifier(facepath)
cap=cv2.VideoCapture(0)
sF=1.05
a=0
while (a!=100):
ret, img=cap.read()
gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = facecascade.detectMultiScale(
gray,
scaleFactor= sF,
minNeighbors=8,
minSize=(55, 55),
flags=cv2.CASCADE_SCALE_IMAGE
)
for(x,y,w,h) in faces:
detect=cv2.rectangle(img, (x,y), (x+w, y+h), (255,0,0), 2)
cv2.inshow('face',detect)
cv2.inwrite('E:\box\face'+str(i)+'.jpg',gray)
a+=1
if cv2.waitKey(1) & 0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I tried this code to detect face from video,while compiling I got the following error
gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
can anyone tell me how to overcome this error!!
read error message : src is empty. please use this tutorials to capture video from a camera
a good idea too is to check that facecascade is not empty : facecascade.empty() ?
Since the error is in the cvtColor function, it means that your source image, img is empty. Before calling cvtColor, please check that a valid image has been loaded into img using img.empty().