Ejemplo n.º 1
0
        private void btnCapture_Click(object sender, EventArgs e)
        {
            if (m_lCapFaceCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                m_lCapFaceCfgHandle = -1;
            }
            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }
            textBoxFilePath.Text = "";

            CHCNetSDK.NET_DVR_CAPTURE_FACE_COND struCond = new CHCNetSDK.NET_DVR_CAPTURE_FACE_COND();
            struCond.init();
            struCond.dwSize = Marshal.SizeOf(struCond);
            int    dwInBufferSize = struCond.dwSize;
            IntPtr ptrStruCond    = Marshal.AllocHGlobal(dwInBufferSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);
            m_lCapFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_CAPTURE_FACE_INFO, ptrStruCond, dwInBufferSize, null, IntPtr.Zero);
            if (-1 == m_lCapFaceCfgHandle)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_CAP_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG struFaceCfg = new CHCNetSDK.NET_DVR_CAPTURE_FACE_CFG();
            struFaceCfg.init();
            int  dwStatus      = 0;
            int  dwOutBuffSize = Marshal.SizeOf(struFaceCfg);
            bool Flag          = true;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lCapFaceCfgHandle, ref struFaceCfg, dwOutBuffSize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessCapFaceData(ref struFaceCfg, ref Flag);
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lCapFaceCfgHandle);
                    break;
                }
            }
            Marshal.FreeHGlobal(ptrStruCond);
        }
Ejemplo n.º 2
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            if (m_lGetFaceCfgHandle != -1)
            {
                CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceCfgHandle);
                m_lGetFaceCfgHandle = -1;
            }

            if (pictureBoxFace.Image != null)
            {
                pictureBoxFace.Image.Dispose();
                pictureBoxFace.Image = null;
            }

            CHCNetSDK.NET_DVR_FACE_COND struCond = new CHCNetSDK.NET_DVR_FACE_COND();
            struCond.init();
            struCond.dwSize = Marshal.SizeOf(struCond);
            int dwSize = struCond.dwSize;

            if (textBoxCardReaderNo.Text.ToString() == "")
            {
                struCond.dwEnableReaderNo = 0;
            }
            else
            {
                int.TryParse(textBoxCardReaderNo.Text.ToString(), out struCond.dwEnableReaderNo);
            }
            struCond.dwFaceNum = 1;//人脸数量是1
            byte[] byTemp = System.Text.Encoding.UTF8.GetBytes(textBoxCardNo.Text);
            for (int i = 0; i < byTemp.Length; i++)
            {
                struCond.byCardNo[i] = byTemp[i];
            }

            IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);

            Marshal.StructureToPtr(struCond, ptrStruCond, false);

            m_lGetFaceCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_UserID, CHCNetSDK.NET_DVR_GET_FACE, ptrStruCond, dwSize, null, IntPtr.Zero);
            if (m_lGetFaceCfgHandle == -1)
            {
                Marshal.FreeHGlobal(ptrStruCond);
                MessageBox.Show("NET_DVR_GET_FACE_FAIL, ERROR CODE" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                return;
            }

            bool Flag     = true;
            int  dwStatus = 0;

            CHCNetSDK.NET_DVR_FACE_RECORD struRecord = new CHCNetSDK.NET_DVR_FACE_RECORD();
            struRecord.init();
            struRecord.dwSize = Marshal.SizeOf(struRecord);
            int dwOutBuffSize = struRecord.dwSize;

            while (Flag)
            {
                dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(m_lGetFaceCfgHandle, ref struRecord, dwOutBuffSize);
                switch (dwStatus)
                {
                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS:    //成功读取到数据,处理完本次数据后需调用next
                    ProcessFaceData(ref struRecord, ref Flag);
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceCfgHandle);
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FAILED" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    break;

                case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
                    MessageBox.Show("NET_SDK_GET_NEXT_STATUS_FINISH", "Tips", MessageBoxButtons.OK);
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceCfgHandle);
                    Flag = false;
                    break;

                default:
                    MessageBox.Show("NET_SDK_GET_STATUS_UNKOWN" + CHCNetSDK.NET_DVR_GetLastError().ToString(), "Error", MessageBoxButtons.OK);
                    Flag = false;
                    CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceCfgHandle);
                    break;
                }
            }

            Marshal.FreeHGlobal(ptrStruCond);
        }