Ejemplo n.º 1
0
        //进行一对一对比
        internal float CompareAFace(float fInitFaceCmpRate, int iPorttrail)
        {
            float fScore   = fInitFaceCmpRate;
            int   iFtrSize = 0;

            HWGetFeatureSize(handleLib, ref iFtrSize);

            IntPtr pbFtrID       = Marshal.AllocHGlobal(iFtrSize);
            IntPtr pbFtrLiveFace = Marshal.AllocHGlobal(iFtrSize);

            //如果确定是证件照,可以设Portrait= 1, 否则设Portrait = 0
            HWSetPortrait(handleLib, iPorttrail);

            int iMaxFace = 1;

            HWFaceInfo[] idFaceInfo = new HWFaceInfo[iMaxFace];
            //找身份证上的人脸
            HWRESULT iRst = HWDetectFaceKeyPoints(handleLib, idPhotoData.pixel, idPhotoData.width, idPhotoData.height, ref iMaxFace, ref idFaceInfo);

            if (iRst != S_OK)
            {
                WinCall.TraceMessage("***没找身份证上的人脸");
                Marshal.FreeHGlobal(pbFtrID);
                Marshal.FreeHGlobal(pbFtrLiveFace);
                return(0.0F);
            }
            if (S_OK != HWExtractFeature(handleLib, idPhotoData.pixel, idPhotoData.width, idPhotoData.height, ref idFaceInfo[0], pbFtrID))
            {
                Marshal.FreeHGlobal(pbFtrID);
                Marshal.FreeHGlobal(pbFtrLiveFace);
                return(0.0F);
            }

            //找出现场照片上的人脸
            var hr = S_FAIL;

            lock (lockLivePhoto)
            {
                hr = HWExtractFeature(handleLib, livePhotoData.pixel, livePhotoData.width, livePhotoData.height, ref curLiveFaceInfo, pbFtrLiveFace);
                StoreLivePhoto();
            }
            if (S_OK != hr)
            {
                Marshal.FreeHGlobal(pbFtrID);
                Marshal.FreeHGlobal(pbFtrLiveFace);
                return(0.0F);
            }

            WinCall.TraceMessage("***HWExtractFeature all ok\n");
            HWCompareFeature(handleLib, pbFtrID, pbFtrLiveFace, ref fScore);

            Marshal.FreeHGlobal(pbFtrID);
            Marshal.FreeHGlobal(pbFtrLiveFace);
            return(fScore);
        }
Ejemplo n.º 2
0
        internal bool DetectLivePhoto()
        {
            int iMaxFace = MAX_DETECT_FACES;

            HWRESULT iRst = S_FAIL;

            iRst = HWDetectFaceKeyPoints(handleLib, livePhotoData.pixel, livePhotoData.width, livePhotoData.height, ref iMaxFace, ref detectFaceInfos);
            bool bValid = (S_OK == iRst);

            if (bValid)
            {
                if (iMaxFace > 1)
                {
                    string str = string.Format("***CFaceDetect::DetectLiveFace(), Faces={0}", iMaxFace);
                    WinCall.TraceMessage(str);
                }
                for (int i = 0; i < iMaxFace; i++)
                {
                    HWFaceInfo face = detectFaceInfos[i];
                    if (i == 0)
                    {
                        curLiveFaceInfo = face;
                        continue;
                    }
                    int nMaxH = curLiveFaceInfo.m_FaceRect.bottom - curLiveFaceInfo.m_FaceRect.top;
                    int nMaxW = curLiveFaceInfo.m_FaceRect.right - curLiveFaceInfo.m_FaceRect.left;
                    int nCurH = face.m_FaceRect.bottom - face.m_FaceRect.top;
                    int nCurW = face.m_FaceRect.right - face.m_FaceRect.left;
                    if (nCurW * nCurH > nMaxW * nMaxH)
                    {
                        curLiveFaceInfo = face;
                    }
                }
            }
            return(bValid);
        }
Ejemplo n.º 3
0
 public static extern HWRESULT HWExtractFeature(HW_HANDLE Handle,
                                                IntPtr pImg, int nImgWidth, int nImgHeight,
                                                ref HWFaceInfo pFaceInfo,
                                                IntPtr pOutFeature);