Skip to content

Commit cf28ace

Browse files
Add initial folder structure.
1 parent 6918c70 commit cf28ace

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

face_detect_skimage.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from skimage import data
2+
from skimage.feature import Cascade
3+
4+
import matplotlib.pyplot as plt
5+
from matplotlib import patches
6+
7+
# Load the trained file from the module root.
8+
trained_file = data.lbp_frontal_face_cascade_filename()
9+
10+
# Initialize the detector cascade.
11+
detector = Cascade(trained_file)
12+
13+
img = data.astronaut()
14+
15+
detected = detector.detect_multi_scale(img=img,
16+
scale_factor=1.2,
17+
step_ratio=1,
18+
min_size=(60, 60),
19+
max_size=(123, 123))
20+
21+
plt.imshow(img)
22+
img_desc = plt.gca()
23+
plt.set_cmap('gray')
24+
25+
for patch in detected:
26+
27+
img_desc.add_patch(
28+
patches.Rectangle(
29+
(patch['c'], patch['r']),
30+
patch['width'],
31+
patch['height'],
32+
fill=False,
33+
color='r',
34+
linewidth=2
35+
)
36+
)
37+
38+
plt.show()

pycasa/__init___.py

Whitespace-only changes.

pycasa/tools/__init___.py

Whitespace-only changes.

pycasa/tools/face_detect.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import cv2
2+
import sys
3+
from matplotlib.pyplot import imshow, show
4+
5+
6+
def collect_detected_faces(image_path, casc_path=None, draw_rectangles=False,
7+
show_image=False):
8+
if casc_path is None:
9+
casc_path = "haarcascade_frontalface_default.xml"
10+
11+
# Create the haar cascade
12+
face_cascade = cv2.CascadeClassifier(casc_path)
13+
14+
# Read the image
15+
image = cv2.imread(image_path)
16+
gray = cv2.imread(image_path, 0)
17+
18+
# Detect faces in the image
19+
faces = face_cascade.detectMultiScale(
20+
gray,
21+
scaleFactor=1.1,
22+
minNeighbors=5,
23+
minSize=(30, 30)
24+
# flags = cv2.CV_HAAR_SCALE_IMAGE
25+
)
26+
if draw_rectangles:
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), (0, 255, 0), 2, 4)
30+
31+
if show_image:
32+
imshow(image)
33+
show()
34+
35+
return faces, image
36+
37+
38+
if __name__ == "__main__":
39+
# Get user supplied values
40+
imagePath = sys.argv[1]
41+
cascPath = "haarcascade_frontalface_default.xml"
42+
43+
faces, image = collect_detected_faces(imagePath, draw_rectangles=True,
44+
show_image=True)
45+
print("Found {0} faces!".format(len(faces)))

0 commit comments

Comments
 (0)