Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created January 9, 2013 04:03
Show Gist options
  • Save Superbil/4490462 to your computer and use it in GitHub Desktop.
Save Superbil/4490462 to your computer and use it in GitHub Desktop.
use openCV API to find face test on openCV 2.4.3
#!/usr/bin/env python
load_model = "haarcascade_frontalface_default.xml"
import sys
image_path = sys.argv[1]
# cv api 1
import cv
img = cv.LoadImage(image_path)
haar = cv.Load(load_model)
s = cv.CreateMemStorage()
d = cv.HaarDetectObjects(img, haar, s, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, (100,100))
if d:
for face in d:
print face
# cv api 2
import cv2
img = cv2.imread(image_path)
haar = cv2.CascadeClassifier(load_model)
d2 = haar.detectMultiScale(img, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING)
if d2.any():
for face in d2:
print face
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment