import cv2 #图片人脸识别 img=cv2.imread(r"C:\Games\python\PyCharm Community Edition 2021.3.1\daima\open cv\2.jpg") gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) face_detector = cv2.CascadeClassifier("C:\Games\python\cv2\data\haarcascade_frontalface_alt.xml") faces = face_detector.detectMultiScale(gray, 1.02, 5) for x, y, w, h in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) cv2.imshow("1", img) cv2.waitKey(0) #视频人脸识别 '''cap = cv2.VideoCapture(0) ok, frame = cap.read() face_detector = cv2.CascadeClassifier("C:\Games\python\cv2\data\haarcascade_frontalface_alt.xml") while cap.isOpened(): ok, frame = cap.read() if not ok: break gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) faces = face_detector.detectMultiScale(gray, 1.02, 5) for x, y, w, h in faces: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2) cv2.imshow("1", frame) c = cv2.waitKey(10) if c & 0xFF == ord('q'): cap.release()'''
11-18
926
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-25
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-26
3479
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交