# 以 OpenCV 實現人臉辨識
## 分類檔
- 正臉
- cascade_frontalface_default.xml
- windows 目錄
- C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\cv2\data\haarcascade_frontalface_alt.xml
- C:\Users\nantochang\AppData\Local\Programs\Python\Python38\Lib\site-packages\cv2\data\haarcascade_frontalface_alt.xml
## Sample code
```python=
import cv2
PATH_HAARCASCAD_FRONTFACE_DEFAULT=(r"C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\cv2\data\haarcascade_frontalface_alt.xml")
vid_cam = cv2.VideoCapture(0)
face_detector = cv2.CascadeClassifier(PATH_HAARCASCAD_FRONTFACE_DEFAULT)
while(vid_cam.isOpened()):
ret, image_frame = vid_cam.read()
gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY)
faces = face_detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(image_frame, (x,y), (x+w,y+h), (255,0,0), 2)
cv2.imshow('frame', image_frame)
if cv2.waitKey(100) & 0xFF == ord('q'):
break
vid_cam.release()
cv2.destroyAllWindows()
```
###### tags: `鯉魚國小`