From 6d7bba285459ec085128b785dc6ff3c69a0407b6 Mon Sep 17 00:00:00 2001 From: Dhruv Dhayal <137479629+BlockNotes-4515@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:54:17 +0530 Subject: [PATCH] =?UTF-8?q?Day-8=5FSUMMER=5FTRAINING=5FK-MEANS/IMAGE/VEDIO?= =?UTF-8?q?.=20=F0=9F=98=8E=F0=9F=98=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day-8 Face Label Real-Time (H.W).py | 42 +++++++++++++++++++++++++++++ Day-8 Face Recognizatins (H.W).py | 42 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Day-8 Face Label Real-Time (H.W).py create mode 100644 Day-8 Face Recognizatins (H.W).py diff --git a/Day-8 Face Label Real-Time (H.W).py b/Day-8 Face Label Real-Time (H.W).py new file mode 100644 index 0000000..736ebe4 --- /dev/null +++ b/Day-8 Face Label Real-Time (H.W).py @@ -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(); \ No newline at end of file diff --git a/Day-8 Face Recognizatins (H.W).py b/Day-8 Face Recognizatins (H.W).py new file mode 100644 index 0000000..f562474 --- /dev/null +++ b/Day-8 Face Recognizatins (H.W).py @@ -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(); \ No newline at end of file