mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-07-16 10:03:42 -07:00
upd xlib.image.sd
This commit is contained in:
parent
d02f46dfc7
commit
6b6b6b2d16
3 changed files with 245 additions and 0 deletions
25
xlib/image/sd/calc.py
Normal file
25
xlib/image/sd/calc.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import numpy as np
|
||||
import numpy.linalg as npla
|
||||
|
||||
def dist_to_edges(pts, pt, is_closed=False):
|
||||
"""
|
||||
returns array of dist from pt to edge and projection pt to edges
|
||||
"""
|
||||
if is_closed:
|
||||
a = pts
|
||||
b = np.concatenate( (pts[1:,:], pts[0:1,:]), axis=0 )
|
||||
else:
|
||||
a = pts[:-1,:]
|
||||
b = pts[1:,:]
|
||||
|
||||
pa = pt-a
|
||||
ba = b-a
|
||||
|
||||
div = np.einsum('ij,ij->i', ba, ba)
|
||||
div[div==0]=1
|
||||
h = np.clip( np.einsum('ij,ij->i', pa, ba) / div, 0, 1 )
|
||||
|
||||
x = npla.norm ( pa - ba*h[...,None], axis=1 )
|
||||
|
||||
return x, a+ba*h[...,None]
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue