Skip to content

Instantly share code, notes, and snippets.

@sdshlanta
Created August 3, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdshlanta/e7780ba15f52a362cc7f5604a155d881 to your computer and use it in GitHub Desktop.
Save sdshlanta/e7780ba15f52a362cc7f5604a155d881 to your computer and use it in GitHub Desktop.
A silly thing I made with openCV it detects faces and sticks an image over them
import cv2
import sys
imagePath = sys.argv[1]
cascPath = sys.argv[2]
kronk = cv2.imread(sys.argv[3], -1)
faceCascade = cv2.CascadeClassifier(cascPath)
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
print "Found {0} faces!".format(len(faces))
for (x, y, w, h) in faces:
#because handling transparency is weird
for c in range(0,3):
image[y:y+kronk.shape[0], x:x+kronk.shape[1], c] = kronk[:,:,c] * (kronk[:,:,3]/255.0) + image[y:y+kronk.shape[0], x:x+kronk.shape[1], c] * (1.0 - kronk[:,:,3]/255.0)
cv2.imwrite("out.jpg", image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment