public static void Main(string[] args) { Console.WriteLine("#####################################################"); //init Engine IntPtr pFDWorkMem = Marshal.AllocCoTaskMem(FD_WORKBUF_SIZE); IntPtr pFRWorkMem = Marshal.AllocCoTaskMem(FR_WORKBUF_SIZE); IntPtr hFDEngine = new IntPtr(0); IntPtr ret = AFD_FSDKLibrary.AFD_FSDK_InitialFaceEngine(APPID, FD_SDKKEY, pFDWorkMem, FD_WORKBUF_SIZE, ref (hFDEngine), _AFD_FSDK_OrientPriority.AFD_FSDK_OPF_0_HIGHER_EXT, 32, MAX_FACE_NUM); if (ret.ToInt64() != 0) { Marshal.FreeCoTaskMem(pFDWorkMem); Marshal.FreeCoTaskMem(pFRWorkMem); Console.WriteLine(String.Format("AFD_FSDK_InitialFaceEngine 0x{0:x}", ret)); Environment.Exit(0); } //print FDEngine version AFD_FSDK_Version versionFD = (AFD_FSDK_Version)Marshal.PtrToStructure(AFD_FSDKLibrary.AFD_FSDK_GetVersion(hFDEngine), typeof(AFD_FSDK_Version)); Console.WriteLine(String.Format("{0} {1} {2} {3}", versionFD.lCodebase, versionFD.lMajor, versionFD.lMinor, versionFD.lBuild)); Console.WriteLine(versionFD.Version); Console.WriteLine(versionFD.BuildDate); Console.WriteLine(versionFD.CopyRight); IntPtr hFREngine = new IntPtr(0); ret = AFR_FSDKLibrary.AFR_FSDK_InitialEngine(APPID, FR_SDKKEY, pFRWorkMem, FR_WORKBUF_SIZE, ref (hFREngine)); if (ret.ToInt64() != 0) { AFD_FSDKLibrary.AFD_FSDK_UninitialFaceEngine(hFDEngine); Marshal.FreeCoTaskMem(pFDWorkMem); Marshal.FreeCoTaskMem(pFRWorkMem); Console.WriteLine(String.Format("AFR_FSDK_InitialEngine 0x{0:x}", ret)); Environment.Exit(0); } // print FREngine version AFR_FSDK_Version versionFR = (AFR_FSDK_Version)Marshal.PtrToStructure(AFR_FSDKLibrary.AFR_FSDK_GetVersion(hFREngine), typeof(AFR_FSDK_Version)); Console.WriteLine(String.Format("{0} {1} {2} {3}", versionFR.lCodebase, versionFR.lMajor, versionFR.lMinor, versionFR.lBuild)); Console.WriteLine(versionFR.Version); Console.WriteLine(versionFR.BuildDate); Console.WriteLine(versionFR.CopyRight); //load Image Data ASVLOFFSCREEN inputImgA; ASVLOFFSCREEN inputImgB; if (bUseRAWFile) { String filePathA = "001_640x480_I420.YUV"; int yuv_widthA = 640; int yuv_heightA = 480; int yuv_formatA = ASVL_COLOR_FORMAT.ASVL_PAF_I420; String filePathB = "003_640x480_I420.YUV"; int yuv_widthB = 640; int yuv_heightB = 480; int yuv_formatB = ASVL_COLOR_FORMAT.ASVL_PAF_I420; inputImgA = loadRAWImage(filePathA, yuv_widthA, yuv_heightA, yuv_formatA); inputImgB = loadRAWImage(filePathB, yuv_widthB, yuv_heightB, yuv_formatB); } else { String filePathA = "001.jpg"; String filePathB = "1_9.jpg"; inputImgA = loadImage(filePathA); inputImgB = loadImage(filePathB); } Console.WriteLine(String.Format("similarity between faceA and faceB is {0}", compareFaceSimilarity(hFDEngine, hFREngine, inputImgA, inputImgB))); inputImgA.freeUnmanaged(); inputImgB.freeUnmanaged(); //release Engine AFD_FSDKLibrary.AFD_FSDK_UninitialFaceEngine(hFDEngine); AFR_FSDKLibrary.AFR_FSDK_UninitialEngine(hFREngine); Marshal.FreeCoTaskMem(pFDWorkMem); Marshal.FreeCoTaskMem(pFRWorkMem); Console.WriteLine("#####################################################"); }
public static void Main(string[] args) { Console.WriteLine("#####################################################"); //init Engine IntPtr pFDWorkMem = Marshal.AllocCoTaskMem(FD_WORKBUF_SIZE); IntPtr hFDEngine = new IntPtr(0); IntPtr ret = AFD_FSDKLibrary.AFD_FSDK_InitialFaceEngine(APPID, FD_SDKKEY, pFDWorkMem, FD_WORKBUF_SIZE, ref (hFDEngine), _AFD_FSDK_OrientPriority.AFD_FSDK_OPF_0_HIGHER_EXT, 16, MAX_FACE_NUM); if (ret.ToInt64() != 0) { Marshal.FreeCoTaskMem(pFDWorkMem); Console.WriteLine(String.Format("AFD_FSDK_InitialFaceEngine 0x{0:x}", ret)); Environment.Exit(0); } //print FDEngine version AFD_FSDK_Version versionFD = (AFD_FSDK_Version)Marshal.PtrToStructure(AFD_FSDKLibrary.AFD_FSDK_GetVersion(hFDEngine), typeof(AFD_FSDK_Version)); Console.WriteLine(String.Format("{0} {1} {2} {3}", versionFD.lCodebase, versionFD.lMajor, versionFD.lMinor, versionFD.lBuild)); Console.WriteLine(versionFD.Version); Console.WriteLine(versionFD.BuildDate); Console.WriteLine(versionFD.CopyRight); //load Image Data ASVLOFFSCREEN inputImg; if (bUseYUVFile) { String filePath = "001_640x480_I420.YUV"; int yuv_width = 640; int yuv_height = 480; int yuv_format = ASVL_COLOR_FORMAT.ASVL_PAF_I420; inputImg = loadYUVImage(filePath, yuv_width, yuv_height, yuv_format); } else { String filePath = "003.jpg"; inputImg = loadImage(filePath); } //do Face Detect FaceInfo[] faceInfos = doFaceDetection(hFDEngine, inputImg); for (int i = 0; i < faceInfos.Length; i++) { FaceInfo rect = faceInfos[i]; Console.WriteLine(String.Format("{0} ({1} {2} {3} {4}) orient {5}", i, rect.left, rect.top, rect.right, rect.bottom, rect.orient)); } inputImg.freeUnmanaged(); //release Engine AFD_FSDKLibrary.AFD_FSDK_UninitialFaceEngine(hFDEngine); Marshal.FreeCoTaskMem(pFDWorkMem); Console.WriteLine("#####################################################"); }