From baeb2249ee30144b3eb266d53117b6fae5dadb0c Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Tue, 9 May 2023 14:25:25 +0530 Subject: Enhanced code to handle creation of 'dataset' & 'trainer' folder for saving images and model --- face-detection/01_face_capture_dataset.py | 3 +++ face-detection/02_face_training.py | 3 +++ face-detection/dataset/userdatasetgohere | 0 face-detection/trainer/trainermodelgoeshere | 0 4 files changed, 6 insertions(+) create mode 100644 face-detection/dataset/userdatasetgohere create mode 100644 face-detection/trainer/trainermodelgoeshere (limited to 'face-detection') diff --git a/face-detection/01_face_capture_dataset.py b/face-detection/01_face_capture_dataset.py index ef40a82..d7ac82c 100644 --- a/face-detection/01_face_capture_dataset.py +++ b/face-detection/01_face_capture_dataset.py @@ -40,6 +40,9 @@ while True: #create a bounding box across the detected face cv2.rectangle(frame, (x,y), (x+w,y+h), (255,0,0), 3) #tuple count += 1 # increment count + # if dataset folder doesnt exist create: + if not os.path.exists("dataset"): + os.makedirs("dataset") # Save the captured bounded-grayscaleimage into the datasets folder cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", frameGray[y:y+h,x:x+w]) #req os # Display the original frame to the user diff --git a/face-detection/02_face_training.py b/face-detection/02_face_training.py index 68b21fe..a0d5a43 100644 --- a/face-detection/02_face_training.py +++ b/face-detection/02_face_training.py @@ -26,6 +26,9 @@ print ("\n [INFO] Training faces. It will take a few seconds. Wait ...") faces,ids = getImagesAndLabels(path) #Train the LBPH recognizer using the face samples and their corresponding labels recognizer.train(faces, np.array(ids)) +# if trainer folder doesnt exist create: +if not os.path.exists("trainer"): + os.makedirs("trainer") #save the model into trainer/trainer.yml recognizer.write('trainer/trainer.yml') # Print the numer of faces trained and then exit the program diff --git a/face-detection/dataset/userdatasetgohere b/face-detection/dataset/userdatasetgohere new file mode 100644 index 0000000..e69de29 diff --git a/face-detection/trainer/trainermodelgoeshere b/face-detection/trainer/trainermodelgoeshere new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3