Skip to content

Commit aa56dcd

Browse files
committed
Added README.md and requirements.txt file
1 parent 967b609 commit aa56dcd

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Face Detection with Haar Cascade
2+
3+
---
4+
5+
Face detection is one of the fundamental applications used in face recognition that determines the locations and sizes of human faces in arbitrary (digital) images. It detects only the facial features.
6+
7+
---
8+
9+
### What is Haar Cascade?
10+
11+
It is an Object Detection Algorithm used to identify faces in an image or a real time video. The algorithm uses edge or line detection features proposed by Viola and Jones in their research paper “Rapid Object Detection using a Boosted Cascade of Simple Features” published in 2001.
12+
13+
The __OpenCV GitHub repository__ has the models stored in XML files, and can be read with the OpenCV methods. These include models for face detection, eye detection, upper body and lower body detection, license plate detection etc.
14+
15+
In this project, I applied face detection to some photos from Harry Potter using OpenCV with Python.
16+
17+
---
18+
19+
### Steps
20+
21+
1. Make sure you have Python 3.7 and a text editor installed.
22+
2. Install the required packages using pip install -r requirements.txt.
23+
3. In the main directory Run `python3 face_detection.py` or `python face_detection.py`.
24+
4. Enter the path of the file.
25+
26+
---
27+
28+
### Results
29+
30+
Some Results of the program:
31+
32+
![Harry Potter](./images/harry.png)
33+
34+
![Professor Snape](./images/snape.png)
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
import os
2-
import numpy as np
32
import cv2
4-
import matplotlib.pyplot as plt
5-
import matplotlib.patches as mpatches
63

74
# cascades: https://github.com/opencv/opencv/tree/master/data/haarcascades
85
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
96

7+
108
def read_file(image_path):
119
if os.path.isfile(image_path):
1210
img = cv2.imread(image_path)
1311
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
14-
return True, gray
12+
return True, img, gray
1513

1614
else:
1715
return False, False
1816

19-
while(1):
20-
input_path = str(input("Enter the path of the file: "))
21-
val, img = read_file(input_path)
22-
if val != False:
23-
break
2417

25-
rects = face_cascade.detectMultiScale(img, scaleFactor=1.05,
26-
minNeighbors=10, minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE)
18+
while(True):
19+
input_path = str(input("Enter the path of the file: "))
20+
val, img, gray = read_file(input_path)
21+
if val == True:
22+
break
23+
24+
rects = face_cascade.detectMultiScale(gray, scaleFactor=1.05,
25+
minNeighbors=10, minSize=(30, 30),
26+
flags=cv2.CASCADE_SCALE_IMAGE)
27+
2728

2829
# loop over the bounding boxes
2930
for (x, y, w, h) in rects:
3031
# draw the face bounding box on the image
3132
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
3233

34+
3335
# show the output image
3436
cv2.imshow("Image", img)
3537
cv2.waitKey(0)
945 KB
Loading
198 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
opencv_python==4.5.1.48

0 commit comments

Comments
 (0)