@@ -92,6 +92,45 @@ private FaceRecognition(string directory)
9292 this . _FaceEncoder = LossMetric . Deserialize ( faceRecognitionModel ) ;
9393 }
9494
95+ /// <summary>
96+ /// Initializes a new instance of the <see cref="FaceRecognition"/> class with the instance that contains model binary datum.
97+ /// </summary>
98+ /// <param name="parameter">The instance that contains model binary datum.</param>
99+ /// <exception cref="ArgumentNullException"><paramref name="parameter"/> is null.</exception>
100+ /// <exception cref="NullReferenceException">The model data is null.</exception>
101+ private FaceRecognition ( ModelParameter parameter )
102+ {
103+ if ( parameter == null )
104+ throw new ArgumentNullException ( nameof ( parameter ) ) ;
105+
106+ if ( parameter . PosePredictor5FaceLandmarksModel == null )
107+ throw new NullReferenceException ( nameof ( parameter . PosePredictor5FaceLandmarksModel ) ) ;
108+
109+ if ( parameter . PosePredictor68FaceLandmarksModel == null )
110+ throw new NullReferenceException ( nameof ( parameter . PosePredictor68FaceLandmarksModel ) ) ;
111+
112+ if ( parameter . CnnFaceDetectorModel == null )
113+ throw new NullReferenceException ( nameof ( parameter . CnnFaceDetectorModel ) ) ;
114+
115+ if ( parameter . FaceRecognitionModel == null )
116+ throw new NullReferenceException ( nameof ( parameter . FaceRecognitionModel ) ) ;
117+
118+ this . _FaceDetector ? . Dispose ( ) ;
119+ this . _FaceDetector = DlibDotNet . Dlib . GetFrontalFaceDetector ( ) ;
120+
121+ this . _PosePredictor68Point ? . Dispose ( ) ;
122+ this . _PosePredictor68Point = ShapePredictor . Deserialize ( parameter . PosePredictor68FaceLandmarksModel ) ;
123+
124+ this . _PosePredictor5Point ? . Dispose ( ) ;
125+ this . _PosePredictor5Point = ShapePredictor . Deserialize ( parameter . PosePredictor5FaceLandmarksModel ) ;
126+
127+ this . _CnnFaceDetector ? . Dispose ( ) ;
128+ this . _CnnFaceDetector = LossMmod . Deserialize ( parameter . CnnFaceDetectorModel ) ;
129+
130+ this . _FaceEncoder ? . Dispose ( ) ;
131+ this . _FaceEncoder = LossMetric . Deserialize ( parameter . FaceRecognitionModel ) ;
132+ }
133+
95134 #endregion
96135
97136 #region Properties
@@ -255,6 +294,17 @@ public static FaceRecognition Create(string directory)
255294 return new FaceRecognition ( directory ) ;
256295 }
257296
297+ /// <summary>
298+ /// Create a new instance of the <see cref="FaceRecognition"/> class.
299+ /// </summary>
300+ /// <param name="parameter">The instance that contains model binary datum.</param>
301+ /// <exception cref="ArgumentNullException"><paramref name="parameter"/> is null.</exception>
302+ /// <exception cref="NullReferenceException">The model data is null.</exception>
303+ public static FaceRecognition Create ( ModelParameter parameter )
304+ {
305+ return new FaceRecognition ( parameter ) ;
306+ }
307+
258308 /// <summary>
259309 /// Crop a specified image with enumerable collection of face locations.
260310 /// </summary>
0 commit comments