Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions face_detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Detect face with openCV
Simple script to detect human face.

# Python requirements
Python 3.0 or newer

##How to use it
Double click on file it will open a camera window face will be detected in green box ,press q to quit the session.

## Installation

Use pip to install the necessary package(s).

```bash
pip install -r requirements.txt
```
46 changes: 46 additions & 0 deletions face_detection/haarcascade.xml

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions face_detection/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import cv2

faceCascade = cv2.CascadeClassifier("haarcascade.xml")

video_capture = cv2.VideoCapture(0)

while True:
# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

# Display the resulting frame
cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
1 change: 1 addition & 0 deletions face_detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opencv-python