目前,我正在做最后的项目。但我走入了死胡同,因为我不知道该做什么了。
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
我希望我的代码在图像或在这种情况下面部匹配时关闭,寡妇会自动关闭而不使用waitkey。这也是我第一次在 StackOverflow 上向人们提问,所以我可以为我的问题提供一些你的程序员的知识吗?