25
25
import cv2
26
26
import numpy
27
27
from tqdm import tqdm
28
- from wand .exceptions import BlobError
28
+ from wand .exceptions import BlobError , CoderError
29
29
from wand .image import Image
30
30
31
31
image_ext_ocv = [".bmp" , ".jpeg" , ".jpg" , ".png" ]
@@ -41,7 +41,7 @@ def find_image_files(path: str) -> list[str]:
41
41
for root , dirs , files in os .walk (path ):
42
42
for filename in files :
43
43
name , extension = os .path .splitext (filename )
44
- if extension .lower () in image_ext_ocv or extension in image_ext_wand :
44
+ if extension .lower () in image_ext_ocv or extension . lower () in image_ext_wand :
45
45
paths .append (os .path .join (root , filename ))
46
46
return paths
47
47
@@ -58,10 +58,20 @@ def image_loader(paths: list[str]) -> Iterator[numpy.ndarray]:
58
58
yield image
59
59
elif extension in image_ext_wand :
60
60
try :
61
- image = Image (filename = path )
61
+ wandImage = Image (filename = path )
62
+ wandImage .auto_orient ()
63
+ image = numpy .array (wandImage )
64
+ image = cv2 .cvtColor (image , cv2 .COLOR_RGB2BGR )
65
+ yield image
62
66
except BlobError as e :
63
67
print (f"Warning: could not load { path } , { e } " )
64
68
continue
69
+ except CoderError as e :
70
+ print (f"Warning: failure in wand while loading { path } , { e } " )
71
+
72
+ else :
73
+ print (f"Warning: could not load { path } , { e } " )
74
+ continue
65
75
66
76
67
77
def extract_video_images (video : cv2 .VideoCapture , interval : int = 0 ):
@@ -132,7 +142,7 @@ def process_referance(detector: cv2.FaceDetectorYN, recognizer: cv2.FaceRecogniz
132
142
133
143
recognizer = cv2 .FaceRecognizerSF .create (model = args .match_model , config = "" , backend_id = cv2 .dnn .DNN_BACKEND_DEFAULT , target_id = cv2 .dnn .DNN_TARGET_CPU )
134
144
detector = cv2 .FaceDetectorYN .create (model = args .detect_model , config = "" , input_size = [320 , 320 ],
135
- score_threshold = 0.6 , nms_threshold = 0.3 , top_k = 5000 , backend_id = cv2 .dnn .DNN_BACKEND_DEFAULT , target_id = cv2 .dnn .DNN_TARGET_CPU )
145
+ score_threshold = 0.4 , nms_threshold = 0.2 , top_k = 5000 , backend_id = cv2 .dnn .DNN_BACKEND_DEFAULT , target_id = cv2 .dnn .DNN_TARGET_CPU )
136
146
137
147
referance_features = process_referance (detector , recognizer , args .referance )
138
148
if len (referance_features ) < 1 :
@@ -166,7 +176,7 @@ def process_referance(detector: cv2.FaceDetectorYN, recognizer: cv2.FaceRecogniz
166
176
resized = image
167
177
score , match = contains_face_match (detector , recognizer , resized , referance_features , args .threshold )
168
178
if match and not args .invert or not match and args .invert :
169
- filename = f"{ counter :04} .png "
179
+ filename = f"{ counter :04} .jpg "
170
180
cv2 .imwrite (os .path .join (args .out , filename ), image )
171
181
counter += 1
172
182
progress .set_description (f"{ score :1.2f} " )
0 commit comments