Created
March 24, 2022 23:24
-
-
Save ola0x/4192ca1bddde3e0b4417e7379ec64c94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import sys | |
image = sys.argv[1] | |
image = cv2.imread(image) | |
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") | |
faces = faceCascade.detectMultiScale( | |
gray_img, | |
scaleFactor=1.3, | |
minNeighbors=3, | |
minSize=(30, 30) | |
) | |
print(f"[INFO] Found {len(faces)} Faces!") | |
for (x,y,w,h) in faces: | |
cv2.rectangle(image, (x,y), (x+w, y+h), (0,255,0), 2) | |
roi_obj = image[y:y+h, x:x+w] | |
print("[INFO] Objects found. Saving locally") | |
cv2.imwrite(str(w) + str(h) + "_faces.jpg", roi_obj) | |
status = cv2.imwrite("opencv_face_detected.jpg", image) | |
print("[INFO] Image face_detected.jpg written to the system: ", status) | |
# cv2.imshow("image",image) | |
# cv2.waitKey(0) | |
# cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment