【问题标题】:How to save finger data into a Database and Match finger with c# in ZK4500 Fingerprint Scanner?如何在 ZK4500 指纹扫描仪中将手指数据保存到数据库并使用 c# 匹配手指?
【发布时间】:2019-02-26 04:35:18
【问题描述】:

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

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

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

看不懂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();
}

【问题讨论】:

  • 我投票结束这个问题作为题外话,因为没有问题,只有一个 github 存储库的链接来解决它
  • 我已经撤回了我的近距离投票,你仍然需要阅读关于提问的帮助,这仍然是非常低的质量

标签: c# fingerprint zkteco


【解决方案1】:

一种方法是使用 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;  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多