0% found this document useful (0 votes)
34 views1 page

Addfacesfacerecognition

The document contains a Python script that captures video from a webcam to detect and store facial images. It uses OpenCV for face detection and saves the captured images and associated names into pickle files. The script allows the user to input their name and collects up to 100 face images, which are resized and stored for future use.

Uploaded by

nikhil.goo20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Addfacesfacerecognition

The document contains a Python script that captures video from a webcam to detect and store facial images. It uses OpenCV for face detection and saves the captured images and associated names into pickle files. The script allows the user to input their name and collects up to 100 face images, which are resized and stored for future use.

Uploaded by

nikhil.goo20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import cv2

import pickle
import numpy as np
import os
video=[Link](0)
facedetect=[Link]('data/haarcascade_frontalface_default.xml')

faces_data=[]

i=0

name=input("Enter Your Name: ")

while True:
ret,frame=[Link]()
gray=[Link](frame, cv2.COLOR_BGR2GRAY)
faces=[Link](gray, 1.3 ,5)
for (x,y,w,h) in faces:
crop_img=frame[y:y+h, x:x+w, :]
resized_img=[Link](crop_img, (50,50))
if len(faces_data)<=100 and i%10==0:
faces_data.append(resized_img)
i=i+1
[Link](frame, str(len(faces_data)), (50,50), cv2.FONT_HERSHEY_COMPLEX,
1, (50,50,255), 1)
[Link](frame, (x,y), (x+w, y+h), (50,50,255), 1)
[Link]("Frame",frame)
k=[Link](1)
if k==ord('q') or len(faces_data)==100:
break
[Link]()
[Link]()

faces_data=[Link](faces_data)
faces_data=faces_data.reshape(100, -1)

if '[Link]' not in [Link]('data/'):


names=[name]*100
with open('data/[Link]', 'wb') as f:
[Link](names, f)
else:
with open('data/[Link]', 'rb') as f:
names=[Link](f)
names=names+[name]*100
with open('data/[Link]', 'wb') as f:
[Link](names, f)

if 'faces_data.pkl' not in [Link]('data/'):


with open('data/faces_data.pkl', 'wb') as f:
[Link](faces_data, f)
else:
with open('data/faces_data.pkl', 'rb') as f:
faces=[Link](f)
faces=[Link](faces, faces_data, axis=0)
with open('data/faces_data.pkl', 'wb') as f:
[Link](faces, f)

You might also like