mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-06 04:52:13 -07:00
fixed bug when same face can be detected twice
This commit is contained in:
parent
aa523b3f2e
commit
2b264da86b
2 changed files with 22 additions and 7 deletions
|
@ -1,6 +1,9 @@
|
||||||
import numpy as np
|
import operator
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from nnlib import nnlib
|
from nnlib import nnlib
|
||||||
|
|
||||||
class S3FDExtractor(object):
|
class S3FDExtractor(object):
|
||||||
|
@ -19,7 +22,7 @@ class S3FDExtractor(object):
|
||||||
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
|
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
|
||||||
return False #pass exception between __enter__ and __exit__ to outter level
|
return False #pass exception between __enter__ and __exit__ to outter level
|
||||||
|
|
||||||
def extract (self, input_image, is_bgr=True):
|
def extract (self, input_image, is_bgr=True, is_remove_intersects=False):
|
||||||
|
|
||||||
if is_bgr:
|
if is_bgr:
|
||||||
input_image = input_image[:,:,::-1]
|
input_image = input_image[:,:,::-1]
|
||||||
|
@ -45,6 +48,21 @@ class S3FDExtractor(object):
|
||||||
b += bt*0.1 #enlarging bottom line a bit for 2DFAN-4, because default is not enough covering a chin
|
b += bt*0.1 #enlarging bottom line a bit for 2DFAN-4, because default is not enough covering a chin
|
||||||
detected_faces.append ( [int(x) for x in (l,t,r,b) ] )
|
detected_faces.append ( [int(x) for x in (l,t,r,b) ] )
|
||||||
|
|
||||||
|
#sort by largest area first
|
||||||
|
detected_faces = [ [(l,t,r,b), (r-l)*(b-t) ] for (l,t,r,b) in detected_faces ]
|
||||||
|
detected_faces = sorted(detected_faces, key=operator.itemgetter(1), reverse=True )
|
||||||
|
detected_faces = [ x[0] for x in detected_faces]
|
||||||
|
|
||||||
|
if is_remove_intersects:
|
||||||
|
for i in range( len(detected_faces)-1, 0, -1):
|
||||||
|
l1,t1,r1,b1 = detected_faces[i]
|
||||||
|
l0,t0,r0,b0 = detected_faces[i-1]
|
||||||
|
|
||||||
|
dx = min(r0, r1) - max(l0, l1)
|
||||||
|
dy = min(b0, b1) - max(t0, t1)
|
||||||
|
if (dx>=0) and (dy>=0):
|
||||||
|
detected_faces.pop(i)
|
||||||
|
|
||||||
return detected_faces
|
return detected_faces
|
||||||
|
|
||||||
def refine(self, olist):
|
def refine(self, olist):
|
||||||
|
|
|
@ -153,15 +153,11 @@ class ExtractSubprocessor(Subprocessor):
|
||||||
elif rot == 270:
|
elif rot == 270:
|
||||||
rotated_image = image.swapaxes( 0,1 )[::-1,:,:]
|
rotated_image = image.swapaxes( 0,1 )[::-1,:,:]
|
||||||
|
|
||||||
rects = data.rects = self.e.extract (rotated_image, is_bgr=True)
|
rects = data.rects = self.e.extract (rotated_image, is_bgr=True, is_remove_intersects=True)
|
||||||
if len(rects) != 0:
|
if len(rects) != 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.max_faces_from_image != 0 and len(data.rects) > 1:
|
if self.max_faces_from_image != 0 and len(data.rects) > 1:
|
||||||
#sort by largest area first
|
|
||||||
x = [ [(l,t,r,b), (r-l)*(b-t) ] for (l,t,r,b) in data.rects]
|
|
||||||
x = sorted(x, key=operator.itemgetter(1), reverse=True )
|
|
||||||
x = [ a[0] for a in x]
|
|
||||||
data.rects = x[0:self.max_faces_from_image]
|
data.rects = x[0:self.max_faces_from_image]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -893,3 +889,4 @@ def extract_umd_csv(input_file_csv,
|
||||||
io.log_info ('Images found: %d' % (images_found) )
|
io.log_info ('Images found: %d' % (images_found) )
|
||||||
io.log_info ('Faces detected: %d' % (faces_detected) )
|
io.log_info ('Faces detected: %d' % (faces_detected) )
|
||||||
io.log_info ('-------------------------')
|
io.log_info ('-------------------------')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue