Exemple #1
0
        public static AFD_Face DeIntPtr(this AFD_FSDK_FACERES face)
        {
            AFD_Face ret = new AFD_Face()
            {
                faceNumber = face.nFace,
                faceOrient = (int)Marshal.PtrToStructure(face.lfaceOrient, typeof(int)),
                rect       = (MRECT)Marshal.PtrToStructure(face.rcFace, typeof(MRECT))
            };

            return(ret);
        }
Exemple #2
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            int width = 0;

            int height = 0;

            int            pitch = 0;
            OpenFileDialog op1   = new OpenFileDialog();

            if (op1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.ImageLocation = op1.FileName;
            }

            Bitmap bitmap = new Bitmap(pictureBox1.ImageLocation);


            // IntPtr imageDataPtr= bitmap.GetHbitmap();

            byte[] imageData = readBmp(bitmap, 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;

            faceRes = new AFD_FSDK_FACERES();

            IntPtr offInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(offInput));

            Marshal.StructureToPtr(offInput, offInputPtr, false);

            IntPtr faceResPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceRes));

            code = Init.ArcSoft_FIC_FaceDataFeatureExtraction(detectEngine, 0, offInputPtr, ref faceResPtr);
        }
Exemple #3
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);
        }