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 clockwide_angle_between(p1, p2): | |
''' | |
Compute clockwise angle between 2 [x,y] points | |
:param p1: First point | |
:type p1: np.array([x1,y1]) | |
:param p2: Second point | |
:type p2: np.array([x2,y3]) | |
:return: clockwise angle between pt1 and pt2 | |
:rtype: float64 | |
''' |
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
Building OpenCV on Mac with Xcode | |
1. make sure you have all the updates installed, latest Xcode, latest CMake. | |
2. run Xcode, if it suggest to install some developer tools on launch, do it. Then quit it. | |
3. in terminal run "sudo xcode-select --reset" | |
4. wipe opencv build directory. | |
5. run CMake (or cmake-gui&), select opencv source directory and fresh build directory. | |
6. select Xcode project generator, I tried Unix, it may not work similarly well. Just use Xcode, you can still build it from command line. | |
7. add OPENCV_EXTRA_MODULES_PATH directory set to opencv_contrib/modules. | |
8. configure => generate => open project. | |
9. build all. |
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 no_derivs(img, pt1,pt2,thresh=10): | |
''' | |
Test whether there are no image derivatives > thresh between pt1 and pt2 | |
:param img: BGR opencv numpy image | |
:param pt1: first (x,y) point | |
:param pt2: second (x,y) point | |
:param thresh: no image differences > than this amount allowed | |
:return: True if no derivs, else False | |
''' | |
coords = np.around(np.linspace(pt1, pt2, np.linalg.norm(pt1 - pt2))).astype(int) |
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 cv2 | |
def fast_corners(img,border_buffer=0): | |
''' | |
Use the fast corner detector to find (x,y) integer corner locations | |
:param img_resized: | |
:param border_buffer: If >0, prune away kepoints w/in this distance of the boarder | |
:return: key point corner locations: list of int cv2.KeyPoints | |
''' |
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 cv2 | |
import copy | |
from copy import deepcopy | |
def offset_pts_for_circle(radius,db=False): | |
''' | |
Create offset coordinates for a circle around a point. The order of the resulting points will be | |
counter-clockwise | |
:param radius: Radius of circle |
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
#!/usr/bin/env python | |
''' | |
Floodfill sample improved by Gary Bradski to find the contour, convert to polygon, test for qaudrilateral | |
make sure the quadrilateral is convex and find the center of the convex quadrilateral. Also, read in a directory of | |
images, not just one. | |
Usage: | |
floodfill.py <Directory of images> |
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 | |
class BackGroundSegmentor(object): | |
def __init__(self): | |
self.fgbg = cv2.createBackgroundSubtractorMOG2( | |
history=450, varThreshold=50, detectShadows=True) | |
self.fgbg.setNMixtures(3) | |
self.vbg = None |
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
git log --graph --full-history --all --color \ | |
--pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s" |
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] |
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 |
NewerOlder