mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-20 21:43:22 -07:00
code release
This commit is contained in:
parent
b941ba41a3
commit
a902f11f74
354 changed files with 826570 additions and 1 deletions
38
xlib/cv/FaceMarkerLBF/FaceMarkerLBF.py
Normal file
38
xlib/cv/FaceMarkerLBF/FaceMarkerLBF.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from xlib.image import ImageProcessor
|
||||
|
||||
|
||||
class FaceMarkerLBF:
|
||||
def __init__(self):
|
||||
marker = self.marker = cv2.face.createFacemarkLBF()
|
||||
marker.loadModel(str(Path(__file__).parent / 'lbfmodel.yaml'))
|
||||
|
||||
def extract(self, img : np.ndarray):
|
||||
"""
|
||||
arguments
|
||||
|
||||
img np.ndarray HW,HWC,NHWC
|
||||
|
||||
returns
|
||||
|
||||
[N,68,2]
|
||||
"""
|
||||
ip = ImageProcessor(img)
|
||||
|
||||
N,H,W,_ = ip.get_dims()
|
||||
|
||||
feed_img = ip.to_grayscale().to_uint8().get_image('NHWC')
|
||||
|
||||
lmrks_list = []
|
||||
for n in range( max(1,N) ):
|
||||
_, lmrks = self.marker.fit(feed_img[n], np.array([ [0,0,W,H] ]) )
|
||||
lmrks = lmrks[0][0]
|
||||
|
||||
lmrks_list.append(lmrks)
|
||||
|
||||
return np.float32(lmrks_list)
|
||||
|
||||
|
805185
xlib/cv/FaceMarkerLBF/lbfmodel.yaml
Normal file
805185
xlib/cv/FaceMarkerLBF/lbfmodel.yaml
Normal file
File diff suppressed because it is too large
Load diff
2
xlib/cv/__init__.py
Normal file
2
xlib/cv/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from .cv import imread, imwrite
|
||||
from .FaceMarkerLBF.FaceMarkerLBF import FaceMarkerLBF
|
39
xlib/cv/cv.py
Normal file
39
xlib/cv/cv.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
def imread(filepath, flags=cv2.IMREAD_UNCHANGED, loader_func=None, raise_on_error=True) -> np.ndarray:
|
||||
"""
|
||||
same as cv2.imread but allows to open non-english characters path
|
||||
|
||||
arguments
|
||||
|
||||
loader_func(None) callable your own loader for filepath
|
||||
raise_on_error(True) if False - no Exception on error, just None return
|
||||
|
||||
returns
|
||||
np.ndarray
|
||||
|
||||
raises Exception if error and raise_on_error
|
||||
"""
|
||||
try:
|
||||
if loader_func is not None:
|
||||
bytes = bytearray(loader_func(filepath))
|
||||
else:
|
||||
with open(filepath, "rb") as stream:
|
||||
bytes = bytearray(stream.read())
|
||||
numpyarray = np.asarray(bytes, dtype=np.uint8)
|
||||
return cv2.imdecode(numpyarray, flags)
|
||||
except Exception as e:
|
||||
if raise_on_error:
|
||||
raise e
|
||||
return None
|
||||
|
||||
def imwrite(filepath, img, *args):
|
||||
ret, buf = cv2.imencode(filepath.suffix, img, *args)
|
||||
if ret == True:
|
||||
try:
|
||||
with open(filepath, "wb") as stream:
|
||||
stream.write( buf )
|
||||
except:
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue