Skip to content

Instantly share code, notes, and snippets.

@roomrys
roomrys / bip_pulp.py
Created March 11, 2025 05:42
Binary Integer Programming using PuLP
from pulp import *
def get_solver(pulp_cbc_path=pulp_cbc_path) -> PULP_CBC_CMD:
"""Get the solver with the correct path to the cbc executable.
https://github.com/coin-or/pulp/issues/62#issuecomment-2712486686
Args:
pulp_cbc_path (str): The (incorrect) path to the cbc executable.
@roomrys
roomrys / cross_view_tracking_algo_1.py
Last active February 25, 2025 17:28
Cross-view tracking: Algorithm 1
"""Cross-view tracking Algorithm 1: Tracking procedure for each iteration.
@misc{chen2021crossviewtrackingmultihuman3d,
title={Cross-View Tracking for Multi-Human 3D Pose Estimation at over 100 FPS},
author={Long Chen and Haizhou Ai and Rui Chen and Zijie Zhuang and Shuang Liu},
year={2021},
eprint={2003.03972},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2003.03972},
@roomrys
roomrys / sleap_shift_labels_temporally.py
Last active January 24, 2025 02:21
sleap: shift all labels temporally
"""Module to shift all labels in a given file by a given amount."""
from __future__ import annotations
from pathlib import Path
import sleap
from sleap import Labels, LabeledFrame, Video
@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
Last active January 22, 2025 19:00
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