currently, right now I'm doing the final project. But I'm at the dead-end because I don't know what to do anymore.
def draw_boundary(img, classifier, ScaleFactor, minNeighbors, color, text, clf):
gray_image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
features = classifier.detectMultiScale(gray_image, ScaleFactor, minNeighbors)
coords = []
for(x,y,w,h) in features:
cv.rectangle(img, (x,y), (x+w, y+h), color, 2)
id, pred = clf.predict(gray_image[y:y+h, x:x+w])
confidence = int(100*(1-pred/300))
if confidence > 80:
if id == 1:
cv.putText(img,c_name + ": Match",(x, y-5),
cv.FONT_HERSHEY_SIMPLEX, 0.8, color, 1, cv.LINE_AA)
else:
cv.putText(img,"UNKNOWNS",(x, y-5),
cv.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 1, cv.LINE_AA)
break
coords = [x,y,w,h]
return coords
def recognize(img, clf, faceCascade):
coords = draw_boundary(img, faceCascade, 1.1, 10, (255, 255, 255), "Face", clf)
return img
while True:
ret, img = video_capture.read()
img = recognize(img, clf, faceCascade)
cv.imshow("face detection", img)
wk = cv.waitKey(1)
if wk == 13:
break
I want my code to close that when the image or in this case face is matched, the widow closes automatically without using waitkey. and also this is my first time asking people on StackOverflow, so can I have some of your programmer's knowledge for my question?
You have set
waitKey(1)which means the window will close after 1ms. If you want it to be displayed infinitely, usewaitKey(0)which will display the window until a key is pressed. If you want your window to be displayed for 13 seconds, use waitKey(13000).