/// <summary>
        /// 年龄检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <returns>年龄检测结构体</returns>
        private static ASF_AgeInfo AgeEstimation(IntPtr pEngine)
        {
            IntPtr pInfo   = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_AgeInfo>());
            int    retCode = -1;

#if NET5_0
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
#endif
            if (
#if NET5_0
                RuntimeInformation.ProcessArchitecture == Architecture.X64
#else
                Environment.Is64BitProcess
#endif
                )
            {
                retCode = ASFFunctions_Pro_x64.ASFGetAge(pEngine, pInfo);
            }
            else
#if NET5_0
            if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
#endif
            {
                retCode = ASFFunctions_Pro_x86.ASFGetAge(pEngine, pInfo);
            }
#if NET5_0
            else
            {
                throw new NotSupportedException("Only supported Windows x86 x64 and Linux x64");
            }
        }
        /// <summary>
        /// 人脸图像质量检测
        /// </summary>
        /// <param name="pEngine">引擎handle</param>
        /// <param name="imageInfo">LPASF_ImageData 图像数据</param>
        /// <param name="faceInfo">人脸信息</param>
        /// <param name="isMask">是否带口罩 默认不带</param>
        /// <returns>调用结果</returns>
        private static float ASFImageQualityDetectEx(IntPtr pEngine, ASF_SingleFaceInfo faceInfo, IntPtr imageInfo, bool isMask)
        {
            float result = -1;

            try
            {
                IntPtr pSingleFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <Models.ASF_SingleFaceInfo>());
                MemoryUtil.StructureToPtr(faceInfo, pSingleFaceInfo);
                int retCode = -1;
#if NET5_0
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
#endif
                if (
#if NET5_0
                    RuntimeInformation.ProcessArchitecture == Architecture.X64
#else
                    Environment.Is64BitProcess
#endif
                    )
                {
                    retCode = ASFFunctions_Pro_x64.ASFImageQualityDetectEx(pEngine, imageInfo, pSingleFaceInfo, isMask ? 1 : 0, ref result, (int)ASF_DetectModel.ASF_DETECT_MODEL_RGB);
                }
                else
#if NET5_0
                if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
#endif
                {
                    retCode = ASFFunctions_Pro_x86.ASFImageQualityDetectEx(pEngine, imageInfo, pSingleFaceInfo, isMask ? 1 : 0, ref result, (int)ASF_DetectModel.ASF_DETECT_MODEL_RGB);
                }
#if NET5_0
                else
                {
                    throw new NotSupportedException("Only supported Windows x86 x64 and Linux x64");
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
                     RuntimeInformation.ProcessArchitecture == Architecture.X64)
            {
                retCode = ASFFunctions_Pro_Sox64.ASFImageQualityDetectEx(pEngine, imageInfo, pSingleFaceInfo, isMask ? 1 : 0, ref result, (int)ASF_DetectModel.ASF_DETECT_MODEL_RGB);
            }
            else
            {
                throw new NotSupportedException("Only supported Windows x86 x64 and Linux x64");
            }
#endif
                MemoryUtil.Free(ref pSingleFaceInfo);
                if (retCode != 0)
                {
                    result = -1;
                }
            }
Exemple #3
0
        /// <returns></returns>
        /// <summary>
        /// 激活SDK
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="x86SdkKey"></param>
        /// <param name="x64SdkKey"></param>
        /// <param name="sox64Key"></param>
        /// <param name="x86ProActiveKey">永久授权版 秘钥 </param>
        /// <param name="x64ProActiveKey">永久授权版 秘钥 </param>
        /// <param name="sox64ProActiveKey">永久授权版 秘钥 </param>
        /// <returns></returns>
        public static int Activation(string appId, string x86SdkKey, string x64SdkKey, string sox64Key
                                     , string x86ProActiveKey = null, string x64ProActiveKey = null, string sox64ProActiveKey = null)
        {
            int result = -1;

#if NET5_0
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
#endif
            if (
#if NET5_0
                RuntimeInformation.ProcessArchitecture == Architecture.X64
#else
                Environment.Is64BitProcess
#endif
                )
            {
                ASF_ActiveFileInfo aSF_ActiveFileInfo  = default;
                IntPtr             pASF_ActiveFileInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_ActiveFileInfo>());

                if (!string.IsNullOrEmpty(x64ProActiveKey))
                {
                    result = ASFFunctions_Pro_x64.ASFGetActiveFileInfo(pASF_ActiveFileInfo);
                }

                if (result == 0)
                {
                    aSF_ActiveFileInfo = MemoryUtil.PtrToStructure <ASF_ActiveFileInfo>(pASF_ActiveFileInfo);
                }
                if (result == 0 &&
                    long.TryParse(aSF_ActiveFileInfo.EndTime, out long endTime) &&
                    long.TryParse(aSF_ActiveFileInfo.StartTime, out long startTime) &&
                    (DateTime.Now.ToTimestamp() / 1000) < endTime &&
                    (DateTime.Now.ToTimestamp() / 1000) >= startTime &&
                    (aSF_ActiveFileInfo.Platform == "windows_x64" || aSF_ActiveFileInfo.SdkType == "windows_x64"))
                {
                    return(result);
                }

                if (!string.IsNullOrEmpty(x64ProActiveKey))
                {
                    result = ASFFunctions_Pro_x64.ASFOnlineActivation(appId, x64SdkKey, x64ProActiveKey);
                    if (result != 0 &&
                        System.IO.File.Exists("ArcFacePro64.dat"))
                    {
                        System.IO.File.Delete("ArcFacePro64.dat");
                        result = ASFFunctions_Pro_x64.ASFOnlineActivation(appId, x64SdkKey, x64ProActiveKey);
                    }
                }
            }
            else
#if NET5_0
            if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
#endif
            {
                ASF_ActiveFileInfo aSF_ActiveFileInfo  = default;
                IntPtr             pASF_ActiveFileInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_ActiveFileInfo>());

                if (!string.IsNullOrEmpty(x86ProActiveKey))
                {
                    result = ASFFunctions_Pro_x86.ASFGetActiveFileInfo(pASF_ActiveFileInfo);
                }

                if (result == 0)
                {
                    aSF_ActiveFileInfo = MemoryUtil.PtrToStructure <ASF_ActiveFileInfo>(pASF_ActiveFileInfo);
                }
                if (result == 0 &&
                    long.TryParse(aSF_ActiveFileInfo.EndTime, out long endTime) &&
                    long.TryParse(aSF_ActiveFileInfo.StartTime, out long startTime) &&
                    (DateTime.Now.ToTimestamp() / 1000) < endTime &&
                    (DateTime.Now.ToTimestamp() / 1000) >= startTime &&
                    (aSF_ActiveFileInfo.Platform == "windows_x86" || aSF_ActiveFileInfo.SdkType == "windows_x86"))
                {
                    return(result);
                }
                if (!string.IsNullOrEmpty(x86ProActiveKey))
                {
                    result = ASFFunctions_Pro_x86.ASFOnlineActivation(appId, x86SdkKey, x86ProActiveKey);
                    if (result != 0 &&
                        System.IO.File.Exists("ArcFacePro32.dat"))
                    {
                        System.IO.File.Delete("ArcFacePro32.dat");
                        result = ASFFunctions_Pro_x86.ASFOnlineActivation(appId, x86SdkKey, x86ProActiveKey);
                    }
                }
            }
#if NET5_0
            else
            {
                throw new NotSupportedException("Only supported Windows x86 x64 and Linux x64");
            }
        }