@@ -45,9 +45,11 @@ protected IFaceRectGetter faceRectGetterInterface
4545
4646 [ Header ( "[Setting]" ) ]
4747
48- public string dlibShapePredictorFileName ;
48+ [ Tooltip ( "Set the shape predictor file path, relative to the starting point of the \" StreamingAssets\" folder, or absolute path." ) ]
49+ public string dlibShapePredictorFilePath ;
4950
50- public string dlibShapePredictorMobileFileName ;
51+ [ Tooltip ( "Set the shape predictor mobile file path, relative to the starting point of the \" StreamingAssets\" folder, or absolute path." ) ]
52+ public string dlibShapePredictorMobileFilePath ;
5153
5254 [ Header ( "[Debug]" ) ]
5355
@@ -69,11 +71,11 @@ protected IFaceRectGetter faceRectGetterInterface
6971
7072 protected FaceLandmarkDetector faceLandmarkDetector ;
7173
72- protected static readonly string DLIB_SHAPEPREDICTOR_FILENAME_PRESET = "DlibFaceLandmarkDetector/sp_human_face_68.dat" ;
74+ protected static readonly string DLIB_SHAPEPREDICTOR_FILEPATH_PRESET = "DlibFaceLandmarkDetector/sp_human_face_68.dat" ;
7375
74- protected static readonly string DLIB_SHAPEPREDICTOR_MOBILE_FILENAME_PRESET = "DlibFaceLandmarkDetector/sp_human_face_68_for_mobile.dat" ;
76+ protected static readonly string DLIB_SHAPEPREDICTOR_MOBILE_FILEPATH_PRESET = "DlibFaceLandmarkDetector/sp_human_face_68_for_mobile.dat" ;
7577
76- protected string dlibShapePredictorFilePath ;
78+ protected string dlibShapePredictorFileFullPath ;
7779
7880#if UNITY_WEBGL
7981 protected IEnumerator getFilePath_Coroutine ;
@@ -89,37 +91,59 @@ public override string GetDescription()
8991
9092 public override void Setup ( )
9193 {
94+ Dispose ( ) ;
95+
9296 NullCheck ( matSourceGetterInterface , "matSourceGetter" ) ;
9397
94- if ( string . IsNullOrEmpty ( dlibShapePredictorFileName ) )
95- dlibShapePredictorFileName = DLIB_SHAPEPREDICTOR_FILENAME_PRESET ;
98+ if ( string . IsNullOrEmpty ( dlibShapePredictorFilePath ) )
99+ dlibShapePredictorFilePath = DLIB_SHAPEPREDICTOR_FILEPATH_PRESET ;
100+
101+ if ( string . IsNullOrEmpty ( dlibShapePredictorMobileFilePath ) )
102+ dlibShapePredictorMobileFilePath = DLIB_SHAPEPREDICTOR_MOBILE_FILEPATH_PRESET ;
96103
97- if ( string . IsNullOrEmpty ( dlibShapePredictorMobileFileName ) )
98- dlibShapePredictorMobileFileName = DLIB_SHAPEPREDICTOR_MOBILE_FILENAME_PRESET ;
99104
100105#if UNITY_WEBGL
101- getFilePath_Coroutine = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePathAsync ( dlibShapePredictorMobileFileName , ( result ) =>
106+ Uri uri ;
107+ if ( Uri . TryCreate ( dlibShapePredictorMobileFilePath , UriKind . Absolute , out uri ) )
102108 {
103- getFilePath_Coroutine = null ;
104-
105- dlibShapePredictorFilePath = result ;
106- if ( string . IsNullOrEmpty ( dlibShapePredictorFilePath ) )
107- {
108- Debug . LogError ( "shape predictor file does not exist. Please copy from “DlibFaceLandmarkDetector/StreamingAssets/DlibFaceLandmarkDetector/” to “Assets/StreamingAssets/DlibFaceLandmarkDetector/” folder. " ) ;
109- }
109+ dlibShapePredictorFileFullPath = uri . OriginalString ;
110110 Run ( ) ;
111- } ) ;
112- StartCoroutine ( getFilePath_Coroutine ) ;
111+ }
112+ else
113+ {
114+ getFilePath_Coroutine = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePathAsync ( dlibShapePredictorMobileFilePath , ( result ) =>
115+ {
116+ getFilePath_Coroutine = null ;
117+
118+ dlibShapePredictorFileFullPath = result ;
119+ Run ( ) ;
120+ } ) ;
121+ StartCoroutine ( getFilePath_Coroutine ) ;
122+ }
113123#else
124+
114125#if UNITY_ANDROID || UNITY_IOS
115- dlibShapePredictorFilePath = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePath ( dlibShapePredictorMobileFileName ) ;
126+ Uri uri ;
127+ if ( Uri . TryCreate ( dlibShapePredictorMobileFilePath , UriKind . Absolute , out uri ) )
128+ {
129+ dlibShapePredictorFileFullPath = uri . OriginalString ;
130+ }
131+ else
132+ {
133+ dlibShapePredictorFileFullPath = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePath ( dlibShapePredictorMobileFilePath ) ;
134+ }
116135#else
117- dlibShapePredictorFilePath = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePath ( dlibShapePredictorFileName ) ;
118- #endif
119- if ( string . IsNullOrEmpty ( dlibShapePredictorFilePath ) )
136+ Uri uri ;
137+ if ( Uri . TryCreate ( dlibShapePredictorFilePath , UriKind . Absolute , out uri ) )
120138 {
121- Debug . LogError ( "shape predictor file does not exist. Please copy from “DlibFaceLandmarkDetector/StreamingAssets/DlibFaceLandmarkDetector/” to “Assets/StreamingAssets/DlibFaceLandmarkDetector/” folder. " ) ;
139+ dlibShapePredictorFileFullPath = uri . OriginalString ;
140+ }
141+ else
142+ {
143+ dlibShapePredictorFileFullPath = DlibFaceLandmarkDetector . UnityUtils . Utils . getFilePath ( dlibShapePredictorFilePath ) ;
122144 }
145+ #endif
146+
123147 Run ( ) ;
124148#endif
125149 }
@@ -254,7 +278,10 @@ public override void UpdateValue()
254278 public override void Dispose ( )
255279 {
256280 if ( faceLandmarkDetector != null )
281+ {
257282 faceLandmarkDetector . Dispose ( ) ;
283+ faceLandmarkDetector = null ;
284+ }
258285
259286 if ( debugMat != null )
260287 {
@@ -282,7 +309,12 @@ public override void Dispose()
282309
283310 protected virtual void Run ( )
284311 {
285- faceLandmarkDetector = new FaceLandmarkDetector ( dlibShapePredictorFilePath ) ;
312+ if ( string . IsNullOrEmpty ( dlibShapePredictorFileFullPath ) )
313+ {
314+ Debug . LogError ( "shape predictor file does not exist. Please copy from “DlibFaceLandmarkDetector/StreamingAssets/DlibFaceLandmarkDetector/” to “Assets/StreamingAssets/DlibFaceLandmarkDetector/” folder. " ) ;
315+ }
316+
317+ faceLandmarkDetector = new FaceLandmarkDetector ( dlibShapePredictorFileFullPath ) ;
286318
287319 didUpdateFaceLanmarkPoints = false ;
288320 }
0 commit comments