如何在ZK4500指纹扫描仪中将手指数据保存到数据库并用c#匹配手指?

问题描述 投票:-1回答:1

我使用的是ZKFingerSDK 5.3。它有一个c#演示,他们使用内存缓存进行测试,但我需要将手指数据保存到数据库并匹配手指数据以便客户识别。请举例说明如何将手指数据保存到任何数据库((MS SQL / MySQL / sqlite)以及如何匹配。

C#演示项目--https://github.com/emrancu/zk4500

演示中的代码:

 MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                    Bitmap bmp = new Bitmap(ms);
                    this.picFPImg.Image = bmp;


                    String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp);
                    textRes.AppendText("capture template data:" + strShow + "\n");

                    if (IsRegister)
                    {
                        int ret = zkfp.ZKFP_ERR_OK;
                        int fid = 0, score = 0;
                        ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score);

                        if (zkfp.ZKFP_ERR_OK == ret)
                        {
                            textRes.AppendText("This finger was already register by " + fid + "!\n");
                            return;
                        }

                        if (RegisterCount > 0 && zkfp2.DBMatch(mDBHandle, CapTmp, RegTmps[RegisterCount - 1]) <= 0)
                        {
                            textRes.AppendText("Please press the same finger 3 times for the enrollment.\n");
                            return;
                        }

                        Array.Copy(CapTmp, RegTmps[RegisterCount], cbCapTmp);
                        String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp);
                        byte[] blob = zkfp2.Base64ToBlob(strBase64);

                        RegisterCount++;

                        if (RegisterCount >= REGISTER_FINGER_COUNT)
                        {
                            RegisterCount = 0;
                            if (zkfp.ZKFP_ERR_OK == (ret = zkfp2.DBMerge(mDBHandle, RegTmps[0], RegTmps[1], RegTmps[2], RegTmp, ref cbRegTmp)) &&
                                   zkfp.ZKFP_ERR_OK == (ret = zkfp2.DBAdd(mDBHandle, iFid, RegTmp)))
                            {
                                iFid++;
                                textRes.AppendText("enroll succ\n");
                            }
                            else
                            {
                                textRes.AppendText("enroll fail, error code=" + ret + "\n");
                            }
                            IsRegister = false;
                            return;
                        }
                        else
                        {
                            textRes.AppendText("You need to press the " + (REGISTER_FINGER_COUNT - RegisterCount) + " times fingerprint\n");
                        }
                    }

我无法理解zkfp2.DBIdentify(),zkfp2.DBAdd(),zkfp2.DBMerge();

public class zkfp2
{
    public zkfp2();

    public static int AcquireFingerprint(IntPtr devHandle, byte[] imgBuffer, byte[] template, ref int size);
    public static int AcquireFingerprintImage(IntPtr devHandle, byte[] imgbuf);
    public static byte[] Base64ToBlob(string base64Str);
    public static string BlobToBase64(byte[] blob, int nDataLen);
    public static bool ByteArray2Int(byte[] buf, ref int value);
    public static int CloseDevice(IntPtr devHandle);
    public static int DBAdd(IntPtr dbHandle, int fid, byte[] regTemp);
    public static int DBClear(IntPtr dbHandle);
    public static int DBCount(IntPtr dbHandle);
    public static int DBDel(IntPtr dbHandle, int fid);
    public static int DBFree(IntPtr dbHandle);
    public static int DBGetParameter(IntPtr dbHandle, int code, ref int value);
    public static int DBIdentify(IntPtr dbHandle, byte[] temp, ref int fid, ref int score);
    public static IntPtr DBInit();
    public static int DBMatch(IntPtr dbHandle, byte[] temp1, byte[] temp2);
    public static int DBMerge(IntPtr dbHandle, byte[] temp1, byte[] temp2, byte[] temp3, byte[] regTemp, ref int regTempLen);
    public static int DBSetParameter(IntPtr dbHandle, int code, int value);
    public static int ExtractFromImage(IntPtr dbHandle, string FileName, int DPI, byte[] template, ref int size);
    public static int GetDeviceCount();
    public static int GetParameters(IntPtr devHandle, int code, byte[] paramValue, ref int size);
    public static int Init();
    public static bool Int2ByteArray(int value, byte[] buf);
    public static IntPtr OpenDevice(int index);
    public static int SetParameters(IntPtr devHandle, int code, byte[] pramValue, int size);
    public static int Terminate();
}
c# fingerprint zkteco
1个回答
0
投票

一种方法是使用MemoryStream并将字节保存到数据库。你可以这样做:

            MemoryStream fingerprintInfo = new MemoryStream();
            template.Serialize(fingerprintInfo);
            fingerprintInfo.Position = 0;
            BinaryReader binaryReader = new BinaryReader(fingerprintInfo);
            Byte[] byteArray = binaryReader.ReadBytes((Int32)fingerprintInfo.Length);

现在,您可以保存字节,如:

打开SQL连接:

SqlConnection connection = new SqlConnection("...);
SqlCommand command = new SqlCommand(...);
cmd.Parameter.Add("FingerPrint", SqlDbType.Image).Value = byteArray;  
© www.soinside.com 2019 - 2024. All rights reserved.