@@ -52,39 +52,41 @@ def detect_faces(self):
5252 self .metadata ["Number of faces detected" ] = len (detected )
5353
5454
55- # Select image file -----------------------------------------------------------
55+ if __name__ == "__main__" :
5656
57- image_path = join (".." , "sample_images" , "IMG-0311_xmas_2020.JPG" )
58- image_path2 = join (".." , "sample_images" , "owls.jpg" )
57+ # Select image file -------------------------------------------------------
5958
60- img = ImageFile ( )
61- for path in [ image_path , image_path2 ]:
59+ image_path = join ( ".." , "sample_images" , "IMG-0311_xmas_2020.JPG" )
60+ image_path2 = join ( ".." , "sample_images" , "20210802_191429.jpg" )
6261
63- img .filepath = path
62+ img = ImageFile ()
63+ for path in [image_path , image_path2 ]:
6464
65- # Detect faces ------------------------------------------------------------
65+ img . filepath = path
6666
67- img . detect_faces ()
67+ # Detect faces --------------------------------------------------------
6868
69- print ( img .metadata )
69+ img .detect_faces ( )
7070
71- # Visualize results -------------------------------------------------------
71+ print ( img . metadata )
7272
73- plt .imshow (img .to_array ())
74- img_desc = plt .gca ()
75- plt .set_cmap ('gray' )
73+ # Visualize results ---------------------------------------------------
7674
77- for patch in img .faces :
75+ plt .imshow (img .to_array ())
76+ img_desc = plt .gca ()
77+ plt .set_cmap ('gray' )
7878
79- img_desc .add_patch (
80- patches .Rectangle (
81- (patch ['c' ], patch ['r' ]),
82- patch ['width' ],
83- patch ['height' ],
84- fill = False ,
85- color = 'r' ,
86- linewidth = 2
79+ for patch in img .faces :
80+
81+ img_desc .add_patch (
82+ patches .Rectangle (
83+ (patch ['c' ], patch ['r' ]),
84+ patch ['width' ],
85+ patch ['height' ],
86+ fill = False ,
87+ color = 'r' ,
88+ linewidth = 2
89+ )
8790 )
88- )
8991
90- plt .show ()
92+ plt .show ()
0 commit comments