Skip to content

Commit

Permalink
cleanup read_data.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nadje committed Aug 7, 2024
1 parent 492a069 commit 33bba7e
Showing 1 changed file with 1 addition and 107 deletions.
108 changes: 1 addition & 107 deletions src/pupil_labs/automate_custom_events/read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,110 +189,4 @@ def create_gaze_overlay_video(merged_video, video_path, world_timestamps_df, out
extra={"markup": True},
)
cv2.destroyAllWindows()


def read_timestamps(path: Union[str, Path]) -> np.ndarray:
"""Read gaze timestamps from a binary file.gaze psX.time"""
return np.fromfile(str(path), dtype="<u8")


def read_raw(path: Union[str, Path]) -> np.ndarray:
"""Read gaze raw data from a binary file.gaze psX.raw"""
raw_data = np.fromfile(str(path), "<f4")
raw_data_dtype = raw_data.dtype
raw_data.shape = (-1, 2)
return np.asarray(raw_data, dtype=raw_data_dtype)


# def create_gaze_overlay_video(video_path, recpath, merged_dataset, events_df):
# container = av.open(video_path)
# video_stream = container.streams.video[0]
# video_duration = float(video_stream.duration * video_stream.time_base)
# print(f"The video duration is {video_duration}")

# # Read first frame
# with av.open(video_path) as vid_container:
# logging.info("Reading first frame")
# vid_frame = next(vid_container.decode(video=0))

# num_processed_frames = 0
# # Create a new folder to save the gaze overlay video
# new_path = os.path.join(recpath, "gaze_module_video")

# # Check if the directory already exists
# if not os.path.exists(new_path):
# # Create the directory
# os.makedirs(new_path)
# print(f"Directory created at {new_path}")
# else:
# print(f"Directory already exists at {new_path}")

# output_file = os.path.join(new_path, "gaze_overlay_video.mp4")
# print(f"Output file: {output_file}")
# logging.info(
# "[white bold on #0d122a]◎ Gaze Module starts![/]",
# extra={"markup": True},
# )
# with av.open(video_path) as video:
# logging.info("Ready to process video")
# # Prepare the output video
# with av.open(output_file, "w") as out_container:
# out_video = out_container.add_stream(
# "libx264", rate=30, options={"crf": "18"}
# )
# out_video.width = video.streams.video[0].width
# out_video.height = video.streams.video[0].height
# out_video.pix_fmt = "yuv420p"
# out_video.codec_context.time_base = Fraction(1, 30)

# lpts = -1

# # For every frame in the video
# # For every frame in the video
# with Progress() as progress_bar:
# video_task = progress_bar.add_task(
# "📹 Processing video", total=merged_dataset.shape[0]
# )
# progress_bar.add_task("Create gaze overlay..")
# while num_processed_frames < merged_dataset.shape[0]:
# row = merged_dataset.iloc[num_processed_frames]
# # Get the frame
# vid_frame, lpts = get_frame(video, int(row["pts"]), lpts, vid_frame)
# if vid_frame is None:
# break
# img_original = vid_frame.to_ndarray(format="rgb24")
# # Prepare the frame
# frame = cv2.cvtColor(img_original, cv2.COLOR_RGB2BGR)
# frame = np.asarray(frame, dtype=np.float32)
# frame = frame[:, :, :]
# xy = row[["gaze x [px]", "gaze y [px]"]].to_numpy(dtype=np.int32)
# gaze_circle_size = 30

# # make a aoi_circle on the gaze
# if not np.isnan(xy).any():
# cv2.circle(frame, xy, gaze_circle_size, (0, 0, 255), 10)

# # Finally get the frame ready.
# out_ = cv2.normalize(
# frame, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U
# )
# cv2.cvtColor(out_, cv2.COLOR_BGR2RGB, out_)
# np.expand_dims(out_, axis=2)
# out_frame = av.VideoFrame.from_ndarray(out_, format="rgb24")
# for packet in out_video.encode(out_frame):
# out_container.mux(packet)
# if num_processed_frames % 100 == 0:
# logging.info(
# f"Processed {num_processed_frames} frames out of {merged_dataset.shape[0]}"
# )
# progress_bar.advance(video_task)
# progress_bar.refresh()
# num_processed_frames += 1
# out_container.close()
# logging.info(
# "[white bold on #0d122a]◎ Gaze overlay rendering completed! ⚡️[/]",
# extra={"markup": True},
# )
# # save the csvs
# merged_dataset.to_csv(Path(recpath, "render_output.csv"), index=False)
# return new_path

0 comments on commit 33bba7e

Please sign in to comment.