~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to bin/face_detect.py

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python2
2
 
import sys
3
 
import cv2
4
 
import numpy
5
 
 
6
 
# Get user supplied values
7
 
cascPath = sys.argv[1]
8
 
 
9
 
# Create the haar cascade
10
 
faceCascade = cv2.CascadeClassifier(cascPath)
11
 
 
12
 
# Read the image
13
 
video_capture = cv2.VideoCapture(0)
14
 
ret, image = video_capture.read()
15
 
#gray = cv2.cvtColor(image, cv2.CV_BGR2GRAY)
16
 
gray = image
17
 
 
18
 
# Detect faces in the image
19
 
faces = faceCascade.detectMultiScale(
20
 
    gray,
21
 
    scaleFactor=1.1,
22
 
    minNeighbors=5,
23
 
    minSize=(30, 30),
24
 
    flags = cv2.CASCADE_SCALE_IMAGE
25
 
)
26
 
 
27
 
# Draw a rectangle around the faces
28
 
for (x, y, w, h) in faces:
29
 
    cv2.rectangle(image, (x, y), (x+w, y+h), (255, 36, 36), 5)
30
 
 
31
 
cv2.imwrite("processed_shot.png", image)
32
 
 
33
 
 
34
 
 
35
 
cv2.waitKey(0)