Skip to content

Commit

Permalink
extract faces to image list
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDoukhan committed Jun 9, 2023
1 parent bdb71e0 commit 4526295
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion inaFaceAnalyzer/inaFaceAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import pandas as pd
from abc import ABC, abstractmethod
from .opencv_utils import video_iterator, image_iterator, analysisFPS2subsamp_coeff
from .opencv_utils import video_iterator, image_iterator, analysisFPS2subsamp_coeff, imwrite_rgb
from .pyav_utils import video_keyframes_iterator
from .face_tracking import TrackerDetector
from .face_detector import LibFaceDetection, PrecomputedDetector
Expand Down Expand Up @@ -298,6 +298,32 @@ def __call__(self, video_path):
stream = video_keyframes_iterator(video_path, verbose=self.verbose)
return self._process_stream(stream, self.face_detector)

def extract_faces(self, df, video_path, output_dir, oshape=None, bbox_scale=None, ext='png'):
'''
Extract faces found with keyframe analysis to directory output_dir
'''

if oshape is None:
oshape = self.classifier.input_shape[:-1]
if bbox_scale is None:
bbox_scale = self.bbox_scale


vki = video_keyframes_iterator(video_path, verbose=self.verbose)
iframe, frame = next(vki)

detector = PrecomputedDetector(list(df.bbox))

for ituple, t in enumerate(df.itertuples()):
while iframe != t.frame:
iframe, frame = next(vki)
detection = detector(frame)
assert len(detection) == 1, len(detection)
detection = detection[0]
img, _ = preprocess_face(frame, detection, self.bbox2square, bbox_scale, self.face_alignment, oshape, False)
imwrite_rgb('%s/%08d.%s' % (output_dir, ituple, ext), img)



class VideoTracking(FaceAnalyzer):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
license = "MIT",
install_requires=['opencv-contrib-python', 'dlib', 'pandas', 'scikit-learn',
'h5py', 'matplotlib', 'onnxruntime-gpu', 'cheetah3',
'av', 'tensorflow>=2.6', 'pyro4'],
'av', 'tensorflow>=2.6', 'pyro4', 'xlsxwriter'],
extras_require={'doc': ['sphinx-toolbox']},
url = "https://github.com/ina-foss/inaFaceAnalyzer",
packages=['inaFaceAnalyzer'],
Expand Down

0 comments on commit 4526295

Please sign in to comment.