Skip to content

Commit 0186577

Browse files
committed
dlib-cnn rotation scale bugfix
1 parent 584c41e commit 0186577

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

plugins/extract/detect/_base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import os
1616
import traceback
1717
from io import StringIO
18+
from math import sqrt
1819

1920
import cv2
2021
import dlib
21-
from math import sqrt
2222

2323
from lib.gpu_stats import GPUStats
2424
from lib.utils import rotate_landmarks
@@ -100,9 +100,9 @@ def run(self, *args, **kwargs):
100100
Do not override """
101101
try:
102102
self.detect_faces(*args, **kwargs)
103-
except Exception: # pylint: disable=broad-except
104-
logger.error("Caught exception in child process: %s", os.getpid())
105-
# Display traceback if in initialization stage
103+
except Exception as err: # pylint: disable=broad-except
104+
logger.error("Caught exception in child process: %s: %s", os.getpid(), str(err))
105+
# Display traceback if in initialization stage
106106
if not self.init.is_set():
107107
logger.exception("Traceback:")
108108
tb_buffer = StringIO()
@@ -149,10 +149,11 @@ def set_scale(self, image, is_square=False, scale_up=False):
149149
else:
150150
scale = 1.0
151151
logger.trace("Detector scale: %s", scale)
152-
152+
153153
return scale
154154

155-
def set_detect_image(self, input_image, scale):
155+
@staticmethod
156+
def set_detect_image(input_image, scale):
156157
""" Convert the image to RGB and scale """
157158
# pylint: disable=no-member
158159
image = input_image[:, :, ::-1].copy()

plugins/extract/detect/dlib_cnn.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def detect_faces(self, *args, **kwargs):
8080
output=None,
8181
scales=scales)
8282
if not all(faces for faces in processed) and self.rotation != [0]:
83-
processed = self.process_rotations(detect_images, processed)
83+
processed = self.process_rotations(detect_images, processed, scales)
8484
for idx, faces in enumerate(processed):
8585
filename = filenames[idx]
8686
for b_idx, item in enumerate(batch):
@@ -137,7 +137,8 @@ def process_output(self, batch_detected,
137137
indexes=None, rotation_matrix=None, output=None, scales=None):
138138
""" Process the output images """
139139
logger.trace("Processing Output: (batch_detected: %s, indexes: %s, rotation_matrix: %s, "
140-
"output: %s", batch_detected, indexes, rotation_matrix, output)
140+
"output: %s, scales: %s",
141+
batch_detected, indexes, rotation_matrix, output, scales)
141142
output = output if output else list()
142143
for idx, faces in enumerate(batch_detected):
143144
detected_faces = list()
@@ -163,7 +164,7 @@ def process_output(self, batch_detected,
163164
logger.trace("Processed Output: %s", output)
164165
return output
165166

166-
def process_rotations(self, detect_images, processed):
167+
def process_rotations(self, detect_images, processed, scales):
167168
""" Rotate frames missing faces until face is found """
168169
logger.trace("Processing Rotations")
169170
for angle in self.rotation:
@@ -182,7 +183,8 @@ def process_rotations(self, detect_images, processed):
182183
processed = self.process_output(batch_detected,
183184
indexes=indexes,
184185
rotation_matrix=rotmat,
185-
output=processed)
186+
output=processed,
187+
scales=scales)
186188
logger.trace("Processed Rotations")
187189
return processed
188190

0 commit comments

Comments
 (0)