diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-03-18 02:04:59 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-03-18 02:04:59 +0530 |
commit | 0cacd048bf88549de4385d5bec3ed6edcf67859c (patch) | |
tree | 9c105b15a1504e43f8f68f529a0ecedcf07324e5 /face-detection | |
parent | b359223312c8389e672ce1a37fa8ef3d5e70504e (diff) |
01_face_capture_dataset.py
Diffstat (limited to 'face-detection')
-rw-r--r-- | face-detection/01_face_capture_dataset.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/face-detection/01_face_capture_dataset.py b/face-detection/01_face_capture_dataset.py new file mode 100644 index 0000000..327264c --- /dev/null +++ b/face-detection/01_face_capture_dataset.py @@ -0,0 +1,30 @@ +import cv2 +import os +cam = cv2.VideoCapture(0) +cam.set(3, 640) # set video width +cam.set(4, 480) # set video height +face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') +# For each person, enter one numeric face id +face_id = input('\n----Enter User-id and press <return>----') +print("\n Initializing face capture. Look the camera and wait!") +# Initialize individual sampling face count +count = 0 +while(True): + ret, img = cam.read() + gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + faces = face_detector.detectMultiScale(gray, 1.3, 5) + for (x,y,w,h) in faces: + cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 2) + count += 1 # increment + # Save the captured image into the datasets folder + cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y+h,x:x+w]) #req os + cv2.imshow('image', img) + k = cv2.waitKey(100) & 0xff # Press 'ESC' for exiting video + if k == 27: + break + elif count >= 30: # Take 30 face sample and stop video capture + break +# Do a bit of cleanup +print("\n Exiting Program and cleaning up stuff") +cam.release() +cv2.destroyAllWindows() |