26
loading...
This website collects cookies to deliver better user experience
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update
brew install python3
sudo pip3 install --upgrade pip
pip3 install virtualenv
mkdir facevirtual
cd facevirtual
virtualenv facevirtual
source facevirtual/bin/activate
facevirtual
environment so your command prompt will look like this.(facevirtual) username@123 facevirtual %
facevirtual
directory txt file named requirements.txt
and paste inside this bunch of the code.cycler==0.10.0
kiwisolver==1.3.2
matplotlib==3.4.3
numpy==1.21.2
opencv-python==4.5.3.56
Pillow==8.3.2
pyparsing==2.4.7
python-dateutil==2.8.2
six==1.16.0
pip3 install -r requirements.txt
haarcascade_frontalface_default.xml
. Easier for you to save this click this link and press save as to download file into facevirtual
directoryfacevirtual
directory as test.jpg
. face-recognition.py
and save into this for now empty file this bunch of the code you see hereunder. cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
load Cascade Classifier and it is responsible for detecting frontal faces on our source picture. The last thing to know that img = cv2.imread('test.jpg')
load the image we already saved from Wikipedia to process.import cv2 #For importing OpenCV library
import matplotlib.pyplot as plt #For plotting the image
# Read Cascade Classifier
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Reading source image to process, update name of image with your own
img = cv2.imread('test.jpg')
# Detect faces
faces = face_cascade.detectMultiScale(image = img, scaleFactor = 1.1, minNeighbors = 5)
# Draw bounding box around the faces
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 1)
# Showing number of faces detected in the image
print(len(faces),"faces are detected!")
# In this step it does plotting the image with faces detected
finalimg = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
plt.figure(figsize=(12,12))
plt.imshow(finalimg)
plt.axis("off")
plt.show()
requirements.txt
file to install all necessary libraries.python3 face-recognition.py
6 faces are detected!