Skip to content

Instantly share code, notes, and snippets.

@roomrys
roomrys / sleap_instance_groups_from_track_names.py
Created December 14, 2024 00:15
SLEAP: Create `InstanceGroup`s from `Track.name`s
import sleap
from tqdm import tqdm
def main(ds: str, ds_out: str = None):
"""Removes all InstanceGroups and creates new ones based on track names.
Args:
ds: Path to the project file.
ds_out: Path to the output project file.
@roomrys
roomrys / triangulation_timing_vecotrized_vs_looped.py
Last active November 27, 2024 17:05
Triangulation: timing comparison vectorized vs looped DLT implementation
from __future__ import annotations
import time
from collections.abc import Callable
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
@roomrys
roomrys / triangulation_dlt_vectorized_implementation.py
Created November 26, 2024 23:43
Triangulation: DLT Vectorized Implementation
import numpy as np
extrinsics = np.array(
[
[
[-3.11213376e-01, -6.97047702e-01, 6.45964965e-01, -5.55457784e02],
[9.26706235e-01, -7.19443053e-02, 3.68835426e-01, -2.94434950e02],
[-2.10622385e-01, 7.13406278e-01, 6.68348481e-01, -1.90821965e02],
[0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00],
@roomrys
roomrys / triangulation_dlt_vectorized_formulation.py
Last active November 26, 2024 23:42
Triangulation: DLT Vectorized Formulation
import numpy as np
n_cameras = 6
n_coords = 3
# Fill our points and projection matrices with strings so we can verify reshaping
points = np.zeros((n_cameras, n_coords, 2), dtype="U3")
for cam_idx in range(n_cameras):
for coord_idx in range(n_coords):
for point_idx in range(2):
@roomrys
roomrys / trace_methods_and_attrs_of_class.py
Last active November 20, 2024 22:44
Trace calls to methods and attributes of a certain class of interest.
"""Call triangulate function and analyze the traceback of certain functions.
The class containing the methods of interest should be wrapped with the
`trace_method_calls` decorator defined below.
This file serves as an example (excluding the modifications made to the
aniposelib/cameras.py file), follow the TODO instructions below to modify to your needs.
"""
import numpy as np
@roomrys
roomrys / sleap_split_labels_into_subsets.py
Created November 4, 2024 19:28
SLEAP: Split Labels into subsets of specific number
from __future__ import annotations
import os
import random
from pathlib import Path
import sleap
from sleap import Labels
@roomrys
roomrys / sleap_multiview_association.py
Created October 8, 2024 15:52
SLEAP: Multiview Association via Pairs of Views and Fundamental Matrix
"""This module implements cycle consistent matching using pairs of views."""
from __future__ import annotations
from typing import Generator
import cv2
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
@roomrys
roomrys / sleap_slp_summary_csv.py
Created October 4, 2024 21:00
SLEAP: Get a summary CSV of all slp files in a directory
"""Outline number of labeled frames, recording sessions, and video paths for all SLPs in directory.
This script recursively finds SLP files in a directory and outputs a CSV outlining how many labeled frames, recording
sessions, and videos there are in each slp project within a directory.
"""
import pathlib
import pandas as pd
@roomrys
roomrys / sio_find_timestamps_in_roi.py
Created September 25, 2024 18:59
SLEAP-IO: Find timestamps for when an instances is in a ROI.
"""Script to find when an annotation is in a ROI of a given image.
# Installation
```bash
conda create -c conda-forge sleap-io shapely -n sio
```
# Usage
Make changes to the __main__ block at the bottom of the file. Then activate the
environment and run the script.
@roomrys
roomrys / sio_rfid_proofreading_v0.py
Last active September 25, 2024 18:57
SLEAP-IO: Auto-proofread with RFID (v0)
import numpy as np
import pandas as pd
import shapely
import sleap_io as sio
from shapely import Polygon
from sleap_io import Instance, Labels, LabeledFrame, PredictedInstance, Track
def load_rfid_rois(ds_rfid: str):
"""Load a dictionary of RFID ROI `Polygons`.