AnkitSen10 / Ankit

0 stars 0 forks source link

face detection #1

Open AnkitSen10 opened 6 months ago

AnkitSen10 commented 6 months ago

The proposed system aims to overcome the limitations of existing face detection algorithm by adopting a adaptive framework, capable of collating the results of numerous existing detection systems in order to significantly improve recall rates. This approach uses supplementary modalities, invariant to the issues posed to features, to eliminate false detections from collated sets and allow us to produce results with extremely high confidence. The properties we have selected as the bases of detection classification are size and colour, as we believe that filters that consider them can be constructed adaptively, on a per-image basis, ensuring that the variabilities inherent to large-scale imagery can be fully accounted for, and that false detections and actual faces can be accurately distinguished between on a consistent basis. The application of principal component analysis to precise face detection results yields planar size distribution models that we can use to discard results that are either too large or too small to realistically represent faces within given images.

AnkitSen10 commented 6 months ago

import cv2, sys, numpy, os haar_file = 'haarcascade_frontalface_default.xml'

datasets = 'datasets'

sub_data = 'vivek'

path = os.path.join(datasets, sub_data) if not os.path.isdir(path): os.mkdir(path)

(width, height) = (130, 100)

face_cascade = cv2.CascadeClassifier(haar_file) webcam = cv2.VideoCapture(0)

count = 1 while count < 30: (_, im) = webcam.read() gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 4) for (x, y, w, h) in faces: cv2.rectangle(im, (x, y), (x + w, y + h), (255, 0, 0), 2) face = gray[y:y + h, x:x + w] face_resize = cv2.resize(face, (width, height)) cv2.imwrite('% s/% s.png' % (path, count), face_resize) count += 1

cv2.imshow('OpenCV', im) 
key = cv2.waitKey(10) 
if key == 27: 
    break
AnkitSen10 commented 6 months ago

import cv2, sys, numpy, os size = 4 haar_file = 'haarcascade_frontalface_default.xml' datasets = 'datasets'

print('Recognizing Face Please Be in sufficient Lights...')

(images, labels, names, id) = ([], [], {}, 0) for (subdirs, dirs, files) in os.walk(datasets): for subdir in dirs: names[id] = subdir subjectpath = os.path.join(datasets, subdir) for filename in os.listdir(subjectpath): path = subjectpath + '/' + filename label = id images.append(cv2.imread(path, 0)) labels.append(int(label)) id += 1 (width, height) = (130, 100)

(images, labels) = [numpy.array(lis) for lis in [images, labels]]

model = cv2.face.LBPHFaceRecognizer_create() model.train(images, labels)

face_cascade = cv2.CascadeClassifier(haarfile) webcam = cv2.VideoCapture(0) while True: (, im) = webcam.read() gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: cv2.rectangle(im, (x, y), (x + w, y + h), (255, 0, 0), 2) face = gray[y:y + h, x:x + w] face_resize = cv2.resize(face, (width, height)) prediction = model.predict(face_resize) cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0), 3)

    if prediction[1]<500: 

    cv2.putText(im, '% s - %.0f' %

(names[prediction[0]], prediction[1]), (x-10, y-10), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0)) else: cv2.putText(im, 'not recognized', (x-10, y-10), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0))

cv2.imshow('OpenCV', im) 

key = cv2.waitKey(10) 
if key == 27: 
    break