Skip to content

Instantly share code, notes, and snippets.

View faustomorales's full-sized avatar

Fausto Morales faustomorales

View GitHub Profile
import os
import json
import functools
import hashlib
import pandas as pd
# Taken from https://bobbyhadz.com/blog/python-typeerror-object-of-type-ndarray-is-not-json-serializable
class NpEncoder(json.JSONEncoder):
def default(self, obj):
@faustomorales
faustomorales / describe_transform.py
Last active November 11, 2020 22:55
Describe the transformation of corner points between two images using SIFT
import perception.hashers.tools as pht
import numpy as np
import cv2
def describe_transformation(image1, image2, sift, matcher, min_match_count=5, min_inliers=0.8):
"""Get a transformation description between two images by using the top-left and
bottom-right coordinate transformations for each.
Args:
image1: The first image
@faustomorales
faustomorales / pdqhash_speed_comparison.py
Last active November 3, 2020 09:19
Compare PDQ Hash performance using pure Python versus bindings to C++ implementation. Results show 262ms for pure Python and 7ms for the bindings.
# Before running this script, you must clone the ThreatExchange
# repo (containing the pure Python implementation)
# and install the pdqhash package (containing the C bindings).
# You can do this by executing the following at the command line.
# git clone https://github.com/facebook/ThreatExchange.git
# pip install pdqhash
import urllib.request
import timeit
import sys
@faustomorales
faustomorales / stabilize.py
Last active April 7, 2023 12:06
Optical Flow Video Stabilization with OpenCV
import cv2
import numpy as np
# Code assumes that the video lives in the following
# folder and is titled video.wmv.
folder_template = 'data/folder/{0}'
# Reset frequency determines how many frames the
# stabilization will track before resetting to the
# identity transform. May switch to using a maximum
# translation, rotation, scale, etc.
@faustomorales
faustomorales / angular-tableau.js
Created March 6, 2016 05:03
Angular directive to embed Tableau dashboards
/* Using this directive is as easy as 1, 2, 3.
1. Grab the Tableau API JavaScript library as well as this module.
a. <script src="path/to/tableau-2.0.0.min.js"></script>
b. <script src="path/to/angular-tableau.js"></script>
2. Import the module into your app by adding 'angular-tableau' to your dependencies.
3. Use the directive like this:
<tableau-viz height="'500px'"
url="path/to/tableau-dashboard"
filters={'field1':['item1', 'item2'], 'dateField':{'min':startDate, 'max':endDate}}">
</tableau-viz>
// Creates a very pretty duration icon
angular.module('utilities').directive('timeDuration', [function () {
return {
restrict: 'E',
template: '<canvas></canvas>',
link: function (scope, element, attrs) {
var time = attrs.time;
var size = attrs.size ? attrs.size : 50;
var shadow = attrs.hasOwnProperty('shadow');
var background = attrs.background ? attrs.background : '#FFF';