Skip to content

Commit 93c8c8e

Browse files
Structure stage 0 better.
1 parent 80bbcfe commit 93c8c8e

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""" Script analyzing an image, detecting human faces inside it, and printing
2+
EXIF data about it.
3+
"""
4+
from os.path import join
5+
6+
import PIL.Image
7+
from PIL.ExifTags import TAGS
8+
from skimage import data
9+
from skimage.feature import Cascade
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
from matplotlib import patches
13+
14+
# Select image file -----------------------------------------------------------
15+
16+
image_path = join("..", "sample_images", "IMG-0311_xmas_2020.JPG")
17+
image_path2 = join("..", "sample_images", "owls.jpg")
18+
19+
for path in [image_path, image_path2]:
20+
img = PIL.Image.open(path)
21+
22+
img_metadata = {TAGS[k]: v for k, v in img._getexif().items() if k in TAGS}
23+
24+
# Detect faces ------------------------------------------------------------
25+
26+
# Load the trained file from the module root.
27+
trained_file = data.lbp_frontal_face_cascade_filename()
28+
29+
# Initialize the detector cascade.
30+
detector = Cascade(trained_file)
31+
32+
detected = detector.detect_multi_scale(img=np.asarray(img),
33+
scale_factor=1.2,
34+
step_ratio=1,
35+
min_size=(60, 60),
36+
max_size=(600, 600))
37+
38+
img_metadata["Number of faces detected"] = len(detected)
39+
print(img_metadata)
40+
41+
# Visualize results -------------------------------------------------------
42+
43+
plt.imshow(img)
44+
img_desc = plt.gca()
45+
plt.set_cmap('gray')
46+
47+
for patch in detected:
48+
49+
img_desc.add_patch(
50+
patches.Rectangle(
51+
(patch['c'], patch['r']),
52+
patch['width'],
53+
patch['height'],
54+
fill=False,
55+
color='r',
56+
linewidth=2
57+
)
58+
)
59+
60+
plt.show()

stage0_starting_script/face_detect_skimage.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)