Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update face_recognition.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions face_recognition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
import face_recognition
import cv2
import os

# Use generic convention of files, do not hardcode file paths in your code. Here is some sample code to do so:

BASE_DIR = os.path.dirname(__file__)
image_dir = os.path.join(BASE_DIR, 'images')

for root, dirs, files in os.walk(image_dir):
for file in files:
if file.endswith('png') or file.endswith('jpg'):
path = os.path.join(root, file)
label = os.path.basename(os.path.dirname(path))
# print(label, path, sep = ': ')

if label not in target_ids:
target_ids[label] = current_id
current_id += 1
id_ = target_ids[label]


# open image using pillow and convert to grayscale
pil_image = Image.open(path).convert('L')

# Resize image
#final_image = pil_image.resize((540,540), Image.ANTIALIAS)

# convert pil image into numpy array
image_array = np.array(pil_image, 'uint8')
# print(image_array)
faces = face_cascade.detectMultiScale(image_array, scaleFactor = 1.5, minNeighbors = 5)

for (x, y, w, h) in faces:
region_of_interest = image_array[y:y+h, x:x+w]
features.append(region_of_interest)
targets.append(id_)


# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(0)
Expand Down