Skip to content

Commit

Permalink
Added get_cropped_skin_im_shapes method, refactored landmarks_windowing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcodallaba committed May 12, 2022
1 parent e7afc92 commit 05445d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pyVHR/extraction/sig_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def extract_patches(self, videoFileName, region_type, sig_extraction_method):
sig = []
processed_frames_count = 0
self.patch_landmarks = []
self.cropped_skin_im_shapes = [[], []]
with mp_face_mesh.FaceMesh(
max_num_faces=1,
min_detection_confidence=0.5,
Expand Down Expand Up @@ -402,6 +403,10 @@ def extract_patches(self, videoFileName, region_type, sig_extraction_method):

### skin extraction ###
cropped_skin_im, full_skin_im = skin_ex.extract_skin(image, ldmks)

self.cropped_skin_im_shapes[0].append(cropped_skin_im.shape[0])
self.cropped_skin_im_shapes[1].append(cropped_skin_im.shape[1])

else:
cropped_skin_im = np.zeros_like(image)
full_skin_im = np.zeros_like(image)
Expand All @@ -416,7 +421,7 @@ def extract_patches(self, videoFileName, region_type, sig_extraction_method):
sig.append(temp)

# save landmarks coordinates
self.patch_landmarks.append(magic_ldmks[:,0:2])
self.patch_landmarks.append(magic_ldmks[:,0:3])

# visualize patches and skin
if self.visualize_skin == True:
Expand Down Expand Up @@ -455,3 +460,12 @@ def get_landmarks(self):
return np.array(self.patch_landmarks)
else:
return np.empty(0)

def get_cropped_skin_im_shapes(self):
"""
Returns cropped skin shapes with shape [height, width] or empty array
"""
if hasattr(self, "cropped_skin_im_shapes"):
return np.array(self.cropped_skin_im_shapes)
else:
return np.empty((0, 0))
8 changes: 6 additions & 2 deletions pyVHR/extraction/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ def sig_windowing(sig, wsize, stride, fps):
block_signals.append(wind_signal)
return block_signals, timesES

def landmarks_windowing(landmarks, wsize, stride, fps):
def movements_windowing(landmarks, area_x, wsize, stride, fps):
"""
Calculation of overlapping windows of landmarks coordinates.
Args:
landmarks (float32 ndarray): ndarray with shape [num_frames, num_estimators, 2-coords].
area_x (float32 ndarray) : ndarray with shape [num_frames]
wsize (float) : window size in seconds.
stride (float) : stride between overlapping windows in seconds.
fps (float) : frames per seconds.
Expand All @@ -142,12 +143,15 @@ def landmarks_windowing(landmarks, wsize, stride, fps):
N = landmarks.shape[0]
block_idx, timesLmks = sliding_straded_win_idx(N, wsize, stride, fps)
lmks_xy = []
win_area_x = []
for e in block_idx:
st_frame = int(e[0])
end_frame = int(e[-1])
coords = np.copy(landmarks[st_frame: end_frame+1])
area_x_coords = np.copy(area_x[st_frame: end_frame+1])
lmks_xy.append(coords)
return np.array(lmks_xy), timesLmks
win_area_x.append(area_x_coords)
return np.array(lmks_xy), np.array(win_area_x), timesLmks


def raw_windowing(raw_signal, wsize, stride, fps):
Expand Down

0 comments on commit 05445d8

Please sign in to comment.