mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-08 05:51:40 -07:00
upd
This commit is contained in:
parent
4c24f9d41c
commit
3fa93da5e7
3 changed files with 23 additions and 2 deletions
|
@ -30,7 +30,7 @@ def apply_random_hsv_shift(img, mask=None, rnd_state=None):
|
||||||
h, s, v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
|
h, s, v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
|
||||||
h = ( h + rnd_state.randint(360) ) % 360
|
h = ( h + rnd_state.randint(360) ) % 360
|
||||||
s = np.clip ( s + rnd_state.random()-0.5, 0, 1 )
|
s = np.clip ( s + rnd_state.random()-0.5, 0, 1 )
|
||||||
v = np.clip ( v + rnd_state.random()/2-0.25, 0, 1 )
|
v = np.clip ( v + rnd_state.random()-0.5, 0, 1 )
|
||||||
|
|
||||||
result = np.clip( cv2.cvtColor(cv2.merge([h, s, v]), cv2.COLOR_HSV2BGR) , 0, 1 )
|
result = np.clip( cv2.cvtColor(cv2.merge([h, s, v]), cv2.COLOR_HSV2BGR) , 0, 1 )
|
||||||
if mask is not None:
|
if mask is not None:
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
from .draw import *
|
from .draw import *
|
||||||
|
from .calc import *
|
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