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
| # 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
| 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
| 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
| 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
| 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
| #!/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 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
| def text_to_floatlist(pathfile): | |
| f = open(pathfile, 'r') | |
| line = f.readline().strip('[]') | |
| f.close() | |
| return [float(x) for x in line.split()] | |
| #Use | |
| rect = text_to_floatlist(seg_bb[frame_count]) | |
| if(len(rect) < 4): | |
| logger.critical("Length of rectangle not long enough %d",int(len(rect)) ) |
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 | |
| from matplotlib import pyplot as plt | |
| . . . | |
| #DO PYTHON MATPLOTLIB IMAGE DISPLAY | |
| plt.imshow(image_seg) | |
| plt.draw() | |
| plt.show() # , plt.draw(), plt.show() | |
| plt.pause(0.01) |