Skip to content

Commit

Permalink
Day-8_SUMMER_TRAINING_K-MEANS/IMAGE/VEDIO. 😎😍
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockNotes-4515 authored Jul 13, 2024
1 parent f66da7b commit 6d7bba2
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Day-8 Face Label Real-Time (H.W).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import joblib;
import cv2 ;
import numpy as np;
import matplotlib.pyplot as plt;

cam = cv2.VideoCapture(1)
path = "C:\\AIML\\datafiles\\haarcascade_frontalface_default (Practice).xml";
# face detector .
face_detector = cv2.CascadeClassifier(path).

model_path = 'C:\\AIML\datafiles\\orl_face_model_2.xml';
face_model = joblib.load(model_path);

frame=True;
count = 0;
while(frame):
ret,im = cam.read();
im_new = cv2.resize(im, (512,512));

# covert the color (BGR) into grayscale
gray_im = cv2.cvtColor(im_new,cv2.COLOR_BGR2GRAY);

# run your classifier on the image.
faces = face_detector.detectMultiScale(gray_im,scaleFactor=1.1,minNeighbors=10);

# disply the bounding box on all the faces.
for (dx,dy,w,h) in faces:
cv2.rectangle(im_new, (dx,dy),(dx+w,dy+h),(0,0,255),2);
cropped_im = cv2.resize((gray_im[dy-20:(dy+h)+40,dx:(dx+w)]),(92,112));
lb = face_model.predict((cropped_im.reshape(1,-1)));
cv2.putText(im_new,'user: '+str(lb[0]),(dx-5,dy-5),cv2.FONT_HERSHEY_SIMPLEX,1,color=(255,0,0),thickness=2)


cv2.imshow('camera live feed', im_new)
# desired button of your choice .
if cv2.waitKey(1) & 0xFF == ord('q'):
frame=False;
break;


cam.release();
cv2.destroyAllWindows();
42 changes: 42 additions & 0 deletions Day-8 Face Recognizatins (H.W).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import joblib;
import cv2 ;
import numpy as np;
import matplotlib.pyplot as plt;

cam = cv2.VideoCapture(1)
path = "C:\\AIML\\datafiles\\haarcascade_frontalface_default (Practice).xml";
# face detector
face_detector = cv2.CascadeClassifier(path);

model_path = 'C:\\AIML\\datafiles\orl_face_model_2.xml';
face_model = joblib.load(model_path);

frame=True;
count = 0;
while(frame):
ret,im = cam.read();
im_new = cv2.resize(im, (512,512));

# covert the color (BGR) into grayscale.
gray_im = cv2.cvtColor(im_new,cv2.COLOR_BGR2GRAY);

# run your classifier on the image.
faces = face_detector.detectMultiScale(gray_im,scaleFactor=1.1,minNeighbors=10);

# disply the bounding box on all the faces.
for (dx,dy,w,h) in faces:
cv2.rectangle(im_new, (dx,dy),(dx+w,dy+h),(0,0,255),2)
cropped_im = cv2.resize((gray_im[dy-20:(dy+h)+40,dx:(dx+w)]),(92,112)) #Convert in PNG Image format of (112*92);
lb = face_model.predict((cropped_im.reshape(1,-1)))
cv2.putText(im_new,'user: '+str(lb[0]),(dx-5,dy-5),cv2.FONT_HERSHEY_SIMPLEX,1,color=(255,0,0),thickness=2)


cv2.imshow('Camera Live Feed', im_new)
# desired button of your choice .
if cv2.waitKey(1) & 0xFF == ord('q'):
frame=False;
break;


cam.release();
cv2.destroyAllWindows();

0 comments on commit 6d7bba2

Please sign in to comment.