summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-05-13 17:14:54 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-05-13 17:14:54 +0530
commitda7b287e7f6c25b5e345116b02c0d4d4c14a582f (patch)
tree3bb8e5e02391c916c7fbe3eb5fa5ca644dc8a53e
parentf1a484ce942741f76f6a99f770f046a2520b2ed8 (diff)
facedetection: Preventing Overwriting old captures
-rw-r--r--face-detection/01_face_capture_dataset.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/face-detection/01_face_capture_dataset.py b/face-detection/01_face_capture_dataset.py
index edf271e..8c1883e 100644
--- a/face-detection/01_face_capture_dataset.py
+++ b/face-detection/01_face_capture_dataset.py
@@ -42,7 +42,7 @@ while True:
scaleFactor=1.1,# how much the image size is reduced at each image scale-10% reduction
minNeighbors=5, # how many neighbors each candidate rectangle should have to retain it
minSize=(30, 30)# Minimum possible object size. Objects smaller than this size are ignored.
- )
+ )
for (x,y,w,h) in faces:
# Create a bounding box across the detected face
cv2.rectangle(frame, (x,y), (x+w,y+h), BOXCOLOR, 3) # 5 parameters - frame, topleftcoords,bottomrightcooords,boxcolor,thickness
@@ -51,8 +51,15 @@ while True:
# 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])
+ # Save the captured bounded-grayscaleimage into the datasets folder only if the same file doesn't exist
+ file_path = os.path.join("dataset", f"User.{face_id}.{count}.jpg")
+ if os.path.exists(file_path):
+ # Move the existing file to the "old_dataset" folder
+ old_file_path = file_path.replace("dataset", "old_dataset")
+ os.rename(file_path, old_file_path)
+ # Write the newer images after moving the old images
+ cv2.imwrite(file_path, frame_gray[y:y+h, x:x+w])
+
# Display the original frame to the user
cv2.imshow('FaceCapture', frame)
@@ -63,8 +70,8 @@ while True:
break
elif key == 113: # q key
break
- elif count >= COUNT_LIMIT: # Take COUNT_LIMIT face sample and stop video capture
- break
+ elif count >= COUNT_LIMIT: # Take COUNT_LIMIT face samples and stop video capture
+ break
# Release the camera and close all windows
print("\n [INFO] Exiting Program and cleaning up stuff")