예제 #1
0
        public static HWRESULT HWDetectFaceKeyPoints(HW_HANDLE Handle,
                                                     IntPtr pImg,
                                                     int nImgWidth, int nImgHeight,
                                                     ref int pnMaxFace,
                                                     ref HWFaceInfo[] pFaceInfo)
        {
            if (pnMaxFace <= 0)
            {
                return(S_FAIL);
            }
            int      nSizeStruct = Marshal.SizeOf(typeof(HWFaceInfo));
            IntPtr   ptr         = Marshal.AllocHGlobal(nSizeStruct * pnMaxFace);
            HWRESULT hr          = HWDetectFaceKeyPoints(Handle, pImg, nImgWidth, nImgHeight, ref pnMaxFace, ptr);

            if (hr == S_OK)
            {
                IntPtr ptrData = ptr;
                for (int i = 0; i < pnMaxFace; i++)
                {
                    pFaceInfo[i] = (HWFaceInfo)Marshal.PtrToStructure(ptrData, typeof(HWFaceInfo));
                    ptrData     += nSizeStruct;
                }
            }
            Marshal.FreeHGlobal(ptr);
            return(hr);
        }
예제 #2
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);
        }
예제 #3
0
        public bool InitLib()
        {
            string   strCurdir = Application.StartupPath;
            HWRESULT hRes      = HWInitialD(strCurdir);

            if (S_OK != hRes)
            {
                return(false);
            }
            hRes = HWInitial(ref handleLib, strCurdir);
            bool bInit = (S_OK == hRes);

            if (bInit)
            {
                idPhotoData   = PicPixel.CreatePicPixel(ID_PHOTO_WID, ID_PHOTO_HEI);
                livePhotoData = PicPixel.CreatePicPixel(LIVE_PHOTO_WID, LIVE_PHOTO_HEI);
            }
            return(bInit);
        }
예제 #4
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);
        }