This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def rect_files(start,stop): | |
| startstop = range(start,stop) | |
| for i in startstop: | |
| openstr = "%09d.txt"%(i) #zero justify out to 9 places | |
| file = open(openstr,"w") | |
| file.write("[ 0, 0, 0, 0 ]") | |
| file.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Useful stuff for scripts, Gary Bradski | |
| #Python | |
| ## For python, you should run your files through yapf | |
| sudo pip install yapf | |
| yapf -i <path/file_to_be_yapfed> | |
| ##To convert python 2 to 3 in place: | |
| 2to3 -w <path/file_to_be_converted> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def skeletonize(img): | |
| ''' | |
| Adapted from: | |
| https://opencvpython.blogspot.com/2012/05/skeletonization-using-opencv-python.html | |
| ''' | |
| assert len(img.shape) == 2 #make sure its single channel | |
| size = np.size(img) | |
| tenth_size = size/10 | |
| skel = np.zeros(img.shape,np.uint8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import numpy as np | |
| def connected_components(thresh_img): | |
| thresh_img = mog_mask.copy() | |
| contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, | |
| cv2.CHAIN_APPROX_SIMPLE) | |
| fg_mask = np.zeros(frame.shape[:2], np.uint8) | |
| i = 0 | |
| cs = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import argparse | |
| import os | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--video', help='path to video to convert to images.') | |
| parser.add_argument('--out', help='path to output directory.') | |
| args = parser.parse_args() | |
| if not os.path.exists(args.out): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fdupes -rdN <dir> | |
| # r is recursive | |
| # d is keep the first file of the duplicated files | |
| # N is run silent so you don't have to say yes or no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From https://gist.github.com/zacharybell/8d9b1b25749fe6494511f843361bb167 | |
| import numpy as np | |
| def mean_iou(labels, predictions, n_classes): | |
| mean_iou = 0.0 | |
| seen_classes = 0 | |
| for c in range(n_classes): | |
| labels_c = (labels == c) | |
| pred_c = (predictions == c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import argparse | |
| import cv2 | |
| MIN_PYTHON = (3, 3) | |
| if sys.version_info < MIN_PYTHON: | |
| sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import codecs, json | |
| #In order ot store an numpy array as a .json file | |
| a = np.arange(10).reshape(2,5) # a 2 by 5 array | |
| b = a.tolist() # nested lists with same data, indices | |
| # Obviously, if you already have list, you don't/can't .tolist() it | |
| file_path = "/path.json" ## your path variable | |
| json.dump(b, codecs.open(file_path, 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4) ### this saves the array in .json format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def convert_bin_img_to_corners(img): | |
| ''' | |
| Mark corners with bias being pixels origin as (x,y): (0.5, 0.5) | |
| :param img: Binary image of field | |
| :return: Image of corners marked with 255, all else is 0 | |
| ''' | |
| kernel = np.ones( | |
| (2, 2), np.float32) # Make convolution kernel 2x2 of 0.25s | |
| ret, img_thresh = cv2.threshold( | |
| img, 1, 1, cv2.THRESH_BINARY) # Make img into [0,1] |