Skip to content

Commit ffc4b0a

Browse files
lochhhniksirbi
authored andcommitted
Update conversion example
1 parent 5071d5c commit ffc4b0a

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

examples/SWC-plusmaze_to_benchmark.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import shutil
1414
from pathlib import Path
1515

16-
import sleap_io as sio
17-
1816
from poseinterface.io import annotations_to_coco
1917

2018
# %%
@@ -98,44 +96,18 @@
9896
# Save COCO annotations inside the Frames directory
9997
target_annotations_path = target_frames_dir / f"{video_id}_framelabels.json"
10098

101-
# %%
102-
# Build new filenames for COCO annotations
103-
# ----------------------------------------
104-
# We need to determine the new filenames before calling annotations_to_coco.
105-
# This ensures the JSON file references the renamed frame files,
106-
# not the original source filenames.
107-
108-
# Load annotations to get the order of labeled frames
109-
labels = sio.load_file(source_annotations_path)
110-
111-
# Build list of new filenames matching the order of labeled frames
112-
coco_image_filenames = []
113-
for lf in labels.labeled_frames:
114-
# Extract the original image path from the labeled frame
115-
# For DLC, video.filename is a list of all image paths;
116-
# use frame_idx to get the correct one for this labeled frame
117-
filename = lf.video.filename
118-
if isinstance(filename, list):
119-
filename = filename[lf.frame_idx]
120-
original_path = Path(filename)
121-
# Extract frame number from filename, e.g. "img0042.png" -> "0042"
122-
frame_number = original_path.stem.replace("img", "")
123-
# Create new filename following the naming convention
124-
new_filename = f"{video_id}_frame-{frame_number}.png"
125-
coco_image_filenames.append(new_filename)
126-
12799
# %%
128100
# Convert DLC annotations to COCO format
129101
# --------------------------------------
130102
# Here we use the :func:`annotations_to_coco` function from `poseinterface.io`
131103
# which wraps around `sleap_io` functionality to perform the conversion.
132-
# We pass the new filenames so the JSON references the renamed frames.
133104

134105
annotations_to_coco(
135106
input_path=source_annotations_path,
136107
output_json_path=target_annotations_path,
137-
coco_image_filenames=coco_image_filenames,
138-
coco_visibility_encoding="ternary",
108+
sub_id=subject_id,
109+
ses_id=session_id,
110+
cam_id=view_id,
139111
)
140112
print(f"Saved COCO annotations to: {target_annotations_path}")
141113

0 commit comments

Comments
 (0)