-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c50151
commit b14f305
Showing
5 changed files
with
33,379 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
Day 21 - Face Recognition using python/detect_face_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# !/usr/bin/python3 | ||
import cv2 | ||
|
||
# Load the cascade | ||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | ||
|
||
# Read the input image | ||
img = cv2.imread('SamplePic.jpg') | ||
|
||
# Convert into grayscale | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
|
||
# Detect faces | ||
faces = face_cascade.detectMultiScale(gray, 1.1, 4) | ||
|
||
# Draw rectangle around the faces | ||
for (x, y, w, h) in faces: | ||
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) | ||
|
||
# Display the output | ||
cv2.imshow('img', img) | ||
cv2.waitKey() |
35 changes: 35 additions & 0 deletions
35
Day 21 - Face Recognition using python/detect_face_video.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# !/usr/bin/python3 | ||
import cv2 | ||
|
||
# Load the cascade | ||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | ||
|
||
# To capture video from webcam. | ||
cap = cv2.VideoCapture(0) | ||
# To use a video file as input | ||
# cap = cv2.VideoCapture('filename.mp4') | ||
|
||
while True: | ||
# Read the frame | ||
_, img = cap.read() | ||
|
||
# Convert to grayscale | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
|
||
# Detect the faces | ||
faces = face_cascade.detectMultiScale(gray, 1.1, 4) | ||
|
||
# Draw the rectangle around each face | ||
for (x, y, w, h) in faces: | ||
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) | ||
|
||
# Display | ||
cv2.imshow('img', img) | ||
|
||
# Stop if escape key is pressed | ||
k = cv2.waitKey(30) & 0xff | ||
if k==27: | ||
break | ||
|
||
# Release the VideoCapture object | ||
cap.release() |
Oops, something went wrong.