Example #1
0
        /// <summary>
        /// 获取图片信息
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static ASVLOFFSCREEN ReadBmp(Image image)
        {
            ASVLOFFSCREEN offInput = new ASVLOFFSCREEN();
            //将Image转换为Format24bppRgb格式的BMP
            Bitmap bm = new Bitmap(image);
            //将Bitmap锁定到系统内存中,获得BitmapData
            BitmapData data = bm.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数组中
            MemoryUtil.Copy(ptr, sourceBitArray, 0, soureBitArrayLength);
            int width  = data.Width;
            int height = data.Height;
            int pitch  = Math.Abs(data.Stride);
            //获取去除对齐位后度图像数据
            int line    = width * 3;
            int bgr_len = line * height;

            byte[] destBitArray = new byte[bgr_len];

            /*
             * 图片像素数据在内存中是按行存储,一般图像库都会有一个内存对齐,在每行像素的末尾位置
             * 每行的对齐位会使每行多出一个像素空间(三通道如RGB会多出3个字节,四通道RGBA会多出4个字节)
             * 以下循环目的是去除每行末尾的对齐位,将有效的像素拷贝到新的数组
             */
            for (int i = 0; i < height; ++i)
            {
                Array.Copy(sourceBitArray, i * pitch, destBitArray, i * line, line);
            }
            pitch = line;
            bm.UnlockBits(data);

            IntPtr imageDataPtr = MemoryUtil.Malloc(destBitArray.Length);

            MemoryUtil.Copy(destBitArray, 0, imageDataPtr, destBitArray.Length);
            offInput.u32PixelArrayFormat = ASF_ImagePixelFormat.ASVL_PAF_RGB24_B8G8R8;
            offInput.ppu8Plane           = new IntPtr[4];
            offInput.ppu8Plane[0]        = imageDataPtr;
            offInput.i32Width            = width;
            offInput.i32Height           = height;
            offInput.pi32Pitch           = new int[4];
            offInput.pi32Pitch[0]        = pitch;
            return(offInput);
        }
Example #2
0
        /// <summary>
        /// 证件照特征提取
        /// </summary>
        /// <param name="hFICEngine">FIC 引擎Handle</param>
        /// <param name="isVideo">人脸数据类型 1-视频 0-静态图片</param>
        /// <param name="bitmap">人脸图像原始数据</param>
        /// <returns>人脸特征提取结果</returns>
        public static int IdCardDataFeatureExtraction(IntPtr hFICEngine, Image image)
        {
            lock (locks)
            {
                if (image.Width % 4 != 0)
                {
                    image = ImageUtil.ScaleImage(image, image.Width - (image.Width % 4), image.Height);
                }
                //Bitmap bitmap = new Bitmap(image);
                ASVLOFFSCREEN offInput = ImageUtil.ReadBmp(image);

                IntPtr offInputPtr = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASVLOFFSCREEN>());
                MemoryUtil.StructureToPtr(offInput, offInputPtr);

                IntPtr faceResPtr = MemoryUtil.Malloc(MemoryUtil.SizeOf <AFIC_FSDK_FACERES>());
                int    result     = ASIDCardFunctions.ArcSoft_FIC_IdCardDataFeatureExtraction(hFICEngine, offInputPtr);
                MemoryUtil.Free(offInput.ppu8Plane[0]);
                MemoryUtil.Free(offInputPtr);
                MemoryUtil.Free(faceResPtr);
                return(result);
            }
        }
Example #3
0
        /// <summary>
        /// 人脸特征提取
        /// </summary>
        /// <param name="hFICEngine">FIC 引擎Handle</param>
        /// <param name="isVideo">人脸数据类型 1-视频 0-静态图片</param>
        /// <param name="bitmap">人脸图像原始数据</param>
        /// <returns>人脸检测结果</returns>
        public static int FaceDataFeatureExtraction(IntPtr hFICEngine, bool isVideo, Bitmap bitmap, ref AFIC_FSDK_FACERES faceRes)
        {
            lock (locks)
            {
                int result = -1;
                if (bitmap != null)
                {
                    ASVLOFFSCREEN offInput = ImageUtil.ReadBmp(bitmap);

                    IntPtr offInputPtr = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASVLOFFSCREEN>());
                    MemoryUtil.StructureToPtr(offInput, offInputPtr);

                    IntPtr faceResPtr = MemoryUtil.Malloc(MemoryUtil.SizeOf <AFIC_FSDK_FACERES>());
                    result  = ASIDCardFunctions.ArcSoft_FIC_FaceDataFeatureExtraction(hFICEngine, isVideo, offInputPtr, faceResPtr);
                    faceRes = MemoryUtil.PtrToStructure <AFIC_FSDK_FACERES>(faceResPtr);
                    MemoryUtil.Free(offInput.ppu8Plane[0]);
                    MemoryUtil.Free(offInputPtr);
                    MemoryUtil.Free(faceResPtr);
                }
                return(result);
            }
        }