Ejemplo n.º 1
0
        public static Boolean checkAndMarkFace(Bitmap image)
        {
            // Bitmap image = a;
            BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            //位图中第一个像素数据的地址。它也可以看成是位图中的第一个扫描行
            IntPtr ptr = data.Scan0;
            //定义数组长度
            int soureBitArrayLength = data.Height * Math.Abs(data.Stride);

            byte[] sourceBitArray = new byte[soureBitArrayLength];
            //将bitmap中的内容拷贝到ptr_bgr数组中
            Marshal.Copy(ptr, sourceBitArray, 0, soureBitArrayLength);
            int width  = data.Width;
            int height = data.Height;
            int pitch  = Math.Abs(data.Stride);

            image.UnlockBits(data);
            data = null;

            int line    = width * 3;
            int bgr_len = line * height;

            byte[] destBitArray = new byte[bgr_len];
            for (int i = 0; i < height; ++i)
            {
                Array.Copy(sourceBitArray, i * pitch, destBitArray, i * line, line);
            }
            pitch = line;
            // image.UnlockBits(data);

            byte[] imageData    = destBitArray;//readBmp(image, ref width, ref height, ref pitch);
            IntPtr imageDataPtr = Marshal.AllocHGlobal(imageData.Length);

            Marshal.Copy(imageData, 0, imageDataPtr, imageData.Length);
            ASVLOFFSCREEN offInput = new ASVLOFFSCREEN();

            offInput.u32PixelArrayFormat = 513;
            offInput.ppu8Plane           = new IntPtr[4];
            offInput.ppu8Plane[0]        = imageDataPtr;
            offInput.i32Width            = width;
            offInput.i32Height           = height;
            offInput.pi32Pitch           = new int[4];
            offInput.pi32Pitch[0]        = pitch;
            IntPtr offInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(offInput));

            Marshal.StructureToPtr(offInput, offInputPtr, false);
            AFD_FSDK_FACERES faceRes    = new AFD_FSDK_FACERES();
            IntPtr           faceResPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceRes));

            int detectResult;

            if (!IS32)
            {
                detectResult = AFDFunction.AFD_FSDK_StillImageFaceDetection(detectEngine, offInputPtr, ref faceResPtr);
            }
            else
            {
                detectResult = AFDFunction.AFD_FSDK_StillImageFaceDetection32(detectEngine, offInputPtr, ref faceResPtr);
            }
            if (detectResult != 0)
            {
                //return false;
            }
            faceRes = (AFD_FSDK_FACERES)Marshal.PtrToStructure(faceResPtr, typeof(AFD_FSDK_FACERES));
            bool flag = (faceRes.nFace > 0 && faceRes.nFace < 10);

            Marshal.FreeHGlobal(imageDataPtr);
            Marshal.FreeHGlobal(offInputPtr);


            return(flag);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化项目
        /// </summary>
        public static void Initproject(bool flag)
        {
            if (flag)
            {
                KANGJIA_PATH = AppDomain.CurrentDomain.BaseDirectory;
                System.IO.Directory.SetCurrentDirectory(KANGJIA_PATH);
                if (KANGJIA_PATH.LastIndexOf("\\kangjia\\") > 0)
                {
                    KANGJIA_MAIN_PATH = KANGJIA_PATH.Substring(0, KANGJIA_PATH.LastIndexOf("\\kangjia\\")) + "\\";
                }
                SERVER_IP = OperateIniFile.ReadIniData("HTTPSERVER_IP");
                QR_URL    = OperateIniFile.ReadIniData("QR_URL");


                PRINT = OperateIniFile.ReadIniData("PRINT");// OperateIniFile.ReadIniData("QR_URL");

                LogisTrac.WriteLog(" KANGJIA_MAIN_PATH--" + KANGJIA_MAIN_PATH);
                LogisTrac.WriteLog(" KANGJIA_PATH--" + KANGJIA_PATH);
                try
                {
                    FACE_LENGTH = Convert.ToInt32(OperateIniFile.ReadIniData("FACE_LENGTH"));
                }
                catch { }
                try
                {
                    HAND_LEAVE_TIME = Convert.ToInt32(OperateIniFile.ReadIniData("HAND_LEAVE_TIME"));
                }
                catch { }


                try
                {
                    FINISH_TIME = Convert.ToInt32(OperateIniFile.ReadIniData("FINISH_TIME")) * 1000;
                }
                catch { }
                try
                {
                    INDEX_TIME = Convert.ToInt32(OperateIniFile.ReadIniData("INDEX_TIME")) * 1000;
                }
                catch { }
                try
                {
                    //初始化面部识别引擎
                    if (!AFDFunction.initEng())
                    {
                    }
                }
                catch (Exception ex)
                {
                    LogisTrac.WriteLog(ex);
                }
                try
                {
                    yoyoConst.EQU_SN_LOG = OperateIniFile.ReadSNIniData("EQU_SN_LOG");
                    yoyoConst.initEquType(yoyoConst.EQU_SN_LOG);
                }
                catch
                {
                }
            }
            else
            {
                KANGJIA_PATH      = AppDomain.CurrentDomain.BaseDirectory + "\\kangjia\\";
                KANGJIA_MAIN_PATH = AppDomain.CurrentDomain.BaseDirectory;
                SERVER_IP         = OperateIniFile.ReadVersionIniData("HTTPSERVER_IP");
                try
                {
                    yoyoConst.EQU_SN_LOG = OperateIniFile.ReadSNIniData("EQU_SN_LOG");
                    yoyoConst.initEquType(yoyoConst.EQU_SN_LOG);
                }
                catch
                {
                }
            }
            //设定flash的信息
            initFlash();

            MAC = NetTools.GetMAC();
        }