Created
May 4, 2020 06:21
-
-
Save jaccon/2f7750fc3480e454039fe298f48a729d 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
# Simple Script to detect faces on Images using OpenCV | |
import cv2 | |
import sys | |
# Get user supplied values | |
imagePath = sys.argv[1] | |
cascPath = "./models/haarcascade_frontalface_default.xml" | |
# Create the haar cascade | |
faceCascade = cv2.CascadeClassifier(cascPath) | |
# Read the image | |
image = cv2.imread(imagePath) | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
# Detect faces in the image | |
faces = faceCascade.detectMultiScale( | |
gray, | |
scaleFactor=1.1, | |
minNeighbors=10, | |
minSize=(30, 30) | |
#flags = cv2.CV_HAAR_SCALE_IMAGE | |
) | |
print("Encontradas {0} faces!".format(len(faces))) | |
# Draw a rectangle around the faces | |
for (x, y, w, h) in faces: | |
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) | |
cv2.imshow("OpenCV Detect Faces", image) | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment