Skip to content

Instantly share code, notes, and snippets.

View petered's full-sized avatar

Peter O'Connor petered

  • eagleeyessearch.com
View GitHub Profile
@petered
petered / py3-11-7-env.txt
Created February 26, 2024 17:51
Python 3.11.7 Conda build with Tkinter 8.6.13 - Should fix MacOS Sonoma unresponsive-mouse-click issues.
# Python 3.11.7 Conda build with Tkinter 8.6.13 - Should fix MacOS Sonoma unresponsive-mouse-click issues.
#
# Modified from https://gist.github.com/space-medicine-lab/17ebe2dee2cc9c26c8907db85bfa220e
#
#
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-arm64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/osx-arm64/blas-1.0-openblas.conda
# Author: Peter O'Connor
# This script starts with a pyinstaller spec file, builds a macOS app,
# codesigns it, notarizes it, staples the notarization ticket, and zips it up.
# Full Guide at: https://sites.google.com/site/petesjunkyard/how-to-turn-your-python-program-into-a-working-macos-app
#
# Before using:
# 1) You should have a python app with a main script.
# 2) Become apple developer - See guide https://sites.google.com/site/petesjunkyard/how-to-turn-your-python-program-into-a-working-macos-app
# 3) Install pyinstaller with
# pip install pyinstaller
@petered
petered / test_standalone_dynamic_delta.py
Created January 9, 2023 00:49
How do I to save a stateful TFLite model where shape of state depends on input?
import shutil
import tempfile
from dataclasses import dataclass
from typing import Optional, Callable, Any, Mapping
import os
import numpy as np
import tensorflow as tf
def save_signatures_to_tflite_model(
@petered
petered / video_reader.py
Last active July 20, 2023 21:28
Defines a VideoReader class - which makes it easily to efficiently access frames in a video on request
import hashlib
import itertools
import os
from collections import OrderedDict
from dataclasses import dataclass
from typing import Optional, TypeVar, Generic, Hashable, Any
from typing import Tuple, Iterator
import av
import cv2
@petered
petered / tf_mask_to_boxes.py
Created August 10, 2022 22:43
An algorithm for computing a series of bounding boxes from a boolean mask
import tensorflow as tf
def tf_mask_to_boxes(mask, insert_fake_first_box: bool = False):
"""
Convert a boolean mask to a series of bounding boxes around each segment.
Warning: VERY SLOW (slower than pure python version of same algorithm)
:param mask: A (HxW) boolean mask
@petered
petered / demo_standalone_image_warp_solution.py
Created July 21, 2022 13:53
A fast heatmap-based image warping algorithm
from dataclasses import dataclass
from typing import Optional
import cv2
import numpy as np
import tensorflow as tf
def tf_box_sum_image_from_padded_image(padded_image, width: int):
@petered
petered / demo_standalone_image_warp.py
Last active July 3, 2022 01:19
A rough draft of "image warping from a heat map"
import cv2
import numpy as np
def warp_image_with_heatmap(src_image: 'BGRImageArray', heatmap: 'HeatMapArray') -> 'BGRImageArray':
""" Rough draft of warping an image with a heatmap.
We compute a set of "resampled pixel locations" and then use cv2.remap to resample the image from these points.
Think of heatmap as representing a grid of point masses.
Each heatmap point "pulls" each resampled-pixel-point away from its original location.
@petered
petered / draw_bounding_boxes.py
Last active June 27, 2022 23:27
Simple tool using OpenCV to manually draw bounding boxes on an image, and return the coordinates of those boxes
from typing import Optional, Tuple, Sequence
import cv2
def draw_bboxes_on_image(
image, # A (height, width, 3) unit8 numpy array representing an image
return_relative=False, # True to return box coorinates relative to width/height of image so they will be in [0, 1] interval
window_name='Draw Your Bounding Box', # What to call the window
display_color=(0, 0, 255), # Colour of the displayed box
display_thickness=2 # Thickness of the displayed box
@petered
petered / sync_data_from_dji_sd_card.py
Last active June 26, 2022 18:33
Syncs data from a DJI SD Card to your local file system, renaming files using modified time
import os
import shutil
import sys
from argparse import ArgumentParser
from datetime import datetime
from typing import Optional, Sequence
def modified_timestamp_to_filename(timestamp: float) -> str:
return datetime.fromtimestamp(timestamp).strftime('dji_%Y-%m-%d_%H-%M-%S')
@petered
petered / alignment-surprise
Created September 12, 2018 14:47
2018-09-12 Why Alignment?
<p><script type="math/tex; mode=display" id="MathJax-Element-1">
\newcommand{\pderiv}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\lderiv}[1]{\frac{\partial \mathcal L}{\partial #1}}
\newcommand{\argmax}[1]{\underset{#1}{\operatorname{argmax}}}
\newcommand{\argmin}[1]{\underset{#1}{\operatorname{argmin}}}
\newcommand{\switch}[3]{\begin{cases} #2 & \text{if } {#1} \\ #3 &\text{otherwise}\end{cases}}
\newcommand{\blue}[1]{\color{blue}{#1}}
\newcommand{\red}[1]{\color{red}{#1}}
\newcommand{\overlabel}[2]{\overset{#1}{\overline{#2}}}
\newcommand{\loss}[0]{\mathcal L}