Skip to content

Commit

Permalink
Merge pull request #50 from NET-BYU/update_video_processing.py
Browse files Browse the repository at this point in the history
Update video processing.py
  • Loading branch information
apal6981 authored Sep 1, 2023
2 parents 07dc639 + ba604eb commit 220a3a3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
Binary file added demos/video/resources/pre-processed/Avatar.npz
Binary file not shown.
Binary file added demos/video/resources/pre-processed/Bob_Ross.npz
Binary file not shown.
Binary file added demos/video/resources/pre-processed/Maxwell.npz
Binary file not shown.
Binary file added demos/video/resources/pre-processed/Rick.npz
Binary file not shown.
Binary file added demos/video/resources/pre-processed/Stick_Bug.npz
Binary file not shown.
21 changes: 10 additions & 11 deletions demos/video/video_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

# Create directory for pre-processed videos
path = "./demos/video/resources/videos/"
path_processed = "./demos/video/resources/pre-processed/"
try:
os.mkdir(path)
except:
Expand All @@ -68,18 +69,23 @@ def normalize(x):
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

# Check if the video has already been processed
if not os.path.exists(f"{path}{target[:-4]}.csv"):
processing = True
logger.info(f"processing {target}")
else:
if os.path.exists(f"{path_processed}{target[:-4]}.npz"):
processing = False
logger.info(f"{target} has already been processed")
else:
processing = True
logger.info(f"processing {target}")

# Iterate through all frames in the video
video = np.array([])
while processing:
(ret, frame) = cap.read()
if not ret:
# Reshape the video and save it
video = video.reshape((total_frames, 48, 48))
video = video.astype(np.uint8)
np.savez_compressed(f"{path_processed}{target[:-4]}.npz", video)
logger.info(f"processed {target}")
break

# fmt: off
Expand All @@ -92,12 +98,5 @@ def normalize(x):
video = np.append(video, graySmall) # append the frame to the video
# fmt: on

# Reshape the video and save it
video = video.reshape((total_frames, 48, 48))
video = video.astype(np.uint8)
np.savez_compressed(
f"./demos/video/resources/pre-processed/{target[:-4]}.npz", video
)

# Release the video
cap.release()

0 comments on commit 220a3a3

Please sign in to comment.