File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 9
9
default_onnx_path = f'{ os .path .dirname (__file__ )} /centerface.onnx'
10
10
11
11
12
+ def ensure_rgb (img : np .ndarray ) -> np .ndarray :
13
+ """Convert input image to RGB if it is in RGBA or L format"""
14
+ if img .ndim == 2 : # 1-channel grayscale -> RGB
15
+ img = cv2 .cvtColor (img , cv2 .COLOR_GRAY2RGB )
16
+ elif img .shape [2 ] == 4 : # 4-channel RGBA -> RGB
17
+ img = cv2 .cvtColor (img , cv2 .COLOR_RGBA2RGB )
18
+ return img
19
+
20
+
12
21
class CenterFace :
13
22
def __init__ (self , onnx_path = None , in_shape = None , backend = 'auto' ):
14
23
self .in_shape = in_shape
@@ -71,6 +80,7 @@ def dynamicize_shapes(static_model):
71
80
return dyn_model
72
81
73
82
def __call__ (self , img , threshold = 0.5 ):
83
+ img = ensure_rgb (img )
74
84
self .orig_shape = img .shape [:2 ]
75
85
if self .in_shape is None :
76
86
self .in_shape = self .orig_shape [::- 1 ]
You can’t perform that action at this time.
0 commit comments