mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-07 21:42:08 -07:00
upd
This commit is contained in:
parent
4c24f9d41c
commit
3fa93da5e7
3 changed files with 23 additions and 2 deletions
20
core/imagelib/sd/calc.py
Normal file
20
core/imagelib/sd/calc.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import numpy as np
|
||||
import numpy.linalg as npla
|
||||
|
||||
def dist_to_edges(pts, p):
|
||||
a = pts[:-1,:]
|
||||
b = pts[1:,:]
|
||||
edges = np.concatenate( ( pts[:-1,None,:], pts[1:,None,:] ), axis=-2)
|
||||
|
||||
pa = p-a
|
||||
ba = b-a
|
||||
|
||||
h = np.clip( np.einsum('ij,ij->i', pa, ba) / np.einsum('ij,ij->i', ba, ba), 0, 1 )
|
||||
|
||||
return npla.norm ( pa - ba*h[...,None], axis=1 )
|
||||
|
||||
def nearest_edge_id_and_dist(pts, p):
|
||||
x = dist_to_edges(pts, p)
|
||||
if len(x) != 0:
|
||||
return np.argmin(x), np.min(x)
|
||||
return None, None
|
Loading…
Add table
Add a link
Reference in a new issue