Skip to content

Commit b03f4ba

Browse files
Add metadata collection to script. Improve script to use image files and add default.
1 parent 8eb6879 commit b03f4ba

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

stage0_starting_script/face_detect_skimage.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1+
2+
import PIL.Image
3+
from PIL.ExifTags import TAGS
14
from skimage import data
25
from skimage.feature import Cascade
3-
46
import matplotlib.pyplot as plt
57
from matplotlib import patches
8+
import imageio
9+
import sys
10+
from os.path import join
611

712
# Load the trained file from the module root.
813
trained_file = data.lbp_frontal_face_cascade_filename()
914

1015
# Initialize the detector cascade.
1116
detector = Cascade(trained_file)
1217

13-
img = data.astronaut()
18+
if len(sys.argv) > 1:
19+
image_path = sys.argv[1]
20+
else:
21+
image_path = join("sample_images", "IMG-0311_xmas_2020.JPG")
22+
# image_path = join("sample_images", "owls.jpg")
23+
24+
img = imageio.imread(image_path)
1425

1526
detected = detector.detect_multi_scale(img=img,
1627
scale_factor=1.2,
1728
step_ratio=1,
1829
min_size=(60, 60),
19-
max_size=(123, 123))
30+
max_size=(600, 600))
2031

2132
plt.imshow(img)
2233
img_desc = plt.gca()
@@ -35,4 +46,11 @@
3546
)
3647
)
3748

49+
img = PIL.Image.open(image_path)
50+
51+
data = {TAGS[k]: v for k, v in img._getexif().items() if k in TAGS}
52+
data["Number of faces detected"] = len(detected)
53+
54+
print(data)
55+
3856
plt.show()

0 commit comments

Comments
 (0)