> For the complete documentation index, see [llms.txt](https://capellac.gitbook.io/opencv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://capellac.gitbook.io/opencv/week1/opencv-basics/face-detection.md).

# Face Detection (Cascade Method)

VIOLA & JONES

### I have used cascade method (Probably I'm not ready for deep learning methods :joy: ). First real-time object detection method was created by Viola\&Jones (2001)&#x20;

{% file src="/files/-MACUGbByaPcDw-nbL1x" %}
Cascades
{% endfile %}

```
import cv2
import numpy as np

faceCascade = cv2.CascadeClassifier("Resources/haarcascade_frontalface_default.xml")
img = cv2.imread("Resources/lena.png")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.1, 4)

for (x,y,w,h) in faces:
    cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2, cv2.LINE_4)

cv2.imshow("Output", img)
cv2.waitKey(0)
```
