This file contains 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 matplotlib.pyplot as plt | |
def ccw(A,B,C): | |
return (C[1]-A[1]) * (B[0]-A[0]) > (B[1]-A[1]) * (C[0]-A[0]) | |
def intersect(A,B,C,D): | |
# check AB vs CD | |
return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D) | |
class LineSegment: |
This file contains 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 | |
def ccw(A,B,C): | |
return (C[1]-A[1]) * (B[0]-A[0]) > (B[1]-A[1]) * (C[0]-A[0]) | |
def intersect(A,B,C,D): | |
# check AB vs CD | |
return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D) | |
class LineSegment: | |
def __init__(self,xy1,xy2): |
This file contains 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 matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
import numpy as np | |
""" | |
marge two scatter animation | |
""" | |
fig = plt.figure() |
This file contains 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 bb_intersection_over_union(boxA, boxB): | |
""" calculate IOU score between boxA and boxB | |
Args: | |
boxA : [hori_lo,virt_lo,hori_hi,virt_hi] | |
boxB : [hori_lo,virt_lo,hori_hi,virt_hi] | |
Returns: | |
iou_score | |
""" | |
# determine the (x, y)-coordinates of the intersection rectangle | |
xA = max(boxA[0], boxB[0]) |
This file contains 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
""" | |
# 変更点 | |
- video2activityで画像を出力するフォルダを指定できるように | |
- video2activity('200922_4_10min.mp4','test.csv',visualize=True,visualize_dir='hoge') | |
- ↑の場合 hoge以下に画像が出力される | |
- 動画内でずっと黒色になっている部分を検出して,白く塗りつぶす処理を追加 | |
- video2activity('200922_4_10min.mp4','test.csv',remove_dontmove=True) | |
""" | |
import tqdm | |
import time |
This file contains 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 tqdm | |
import time | |
import pandas as pd | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
from sklearn.cluster import DBSCAN | |
def measure_position(arr,mouse_area_max,mouse_area_min, |
This file contains 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 matplotlib.pyplot as plt | |
import numpy as np | |
def val2color(x): | |
assert x<=1, 'x should be in the [0,1]' | |
base =0.5 | |
if x<1/3: | |
g=x*3. | |
r= 1-g | |
b=0 |
This file contains 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 pprint | |
import numpy as np | |
class PolynomialPredictor(object): | |
def __init__(self,u,v,n=1,debug=True): | |
self.n = n | |
u = np.array(u) | |
A = np.array([u**i for i in range(self.n,-1,-1)]).T | |
b = np.array([v]).T | |
self.alpha = np.matmul(np.matmul( np.linalg.inv( np.matmul(A.T,A) ), A.T ), b ) | |
self.sum_of_se = np.sum((np.matmul(A,np.fliplr(self.alpha))-b)**2) |
This file contains 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 matplotlib.pyplot as plt | |
import matplotlib.patches as pat | |
rot = lambda th:np.array([[np.cos(th),-np.sin(th)],[np.sin(th),np.cos(th)]]) | |
mu = np.array([0.,0.]) | |
S = np.array([[1,0],[0,6]]) @ rot(np.pi/3) | |
x = np.random.multivariate_normal(mu, S,10000) | |
fig = plt.figure(figsize=(10, 10)) | |
ax = fig.add_subplot(111) |
This file contains 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 matplotlib.pyplot as plt | |
import math | |
def xy2color(x,y): | |
norm = min(1.0,(x*x + y*y)**(1/2)) | |
rad = math.atan2(x,y)+math.pi | |
if rad < math.pi*2/3: | |
ratio = rad/(math.pi*2/3) | |
r = 1.-ratio | |
g = ratio | |
b = 0 |
NewerOlder