scaleFactor、ninNeighbors的动态调整 按键:“+”“-”“<”“>”,“q”退出!
import cv2
print("hello")
# camera=cv2.VideoCapture('./腾讯云.mp4')
camera=cv2.VideoCapture(0)
success,img=camera.read()
i=1.3
j=2
while camera.isOpened():
success, img = camera.read()
s=(cv2.waitKey(1) & 0xff)
if s==ord('q'):
break
if s == ord('+'):
i += 0.05
if s == ord('-'):
i -= 0.05
if s == ord('>'):
j += 1
if s == ord('<'):
j -= 1
faceCascade=cv2.CascadeClassifier(r'C:\Users\Administrator\AppData\Local\Programs\Python\Python38\Lib\site-packages\cv2\data\haarcascade_frontalface_alt.xml')
img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(img_gray,scaleFactor=i,minNeighbors=j)
for(x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3)
cv2.putText(img,"scaleFactor:%.2f,minNeighbors:%d"%(i,j),(20,20),cv2.FONT_HERSHEY_COMPLEX,0.8,(0,0,255),2)
cv2.imshow("xxx",img)
camera.release()
cv2.destroyAllWindows()
标签:人脸识别,img,python,cv2,0.05,opencv,camera,ord
From: https://www.cnblogs.com/scientist/p/16795496.html