简体   繁体   中英

How to save finger data into a Database and Match finger with c# in ZK4500 Fingerprint Scanner?

I am using ZKFingerSDK 5.3. It has a demo for c# where they used a memory cache for testing purpose but I need to save finger data to database and match finger data for customer identification. Please give me a example how to save finger data into any database ((MS SQL/MySQL/sqlite) and how to match.

C# Demo Project -- https://github.com/emrancu/zk4500

Code inside Demo:

 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");
                        }
                    }

I can not understand 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();
}

One way is to use MemoryStream and save the bytes to database. You can do something like this:

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

Now, you can save the bytes like:

Open a SQL Connection:

SqlConnection connection = new SqlConnection("...);
SqlCommand command = new SqlCommand(...);
cmd.Parameter.Add("FingerPrint", SqlDbType.Image).Value = byteArray;  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM