private string CompararDigital(string Digital) { uint ret; bool result; NBioAPI m_NBioAPI = new NBioAPI(); NBioAPI.Type.HFIR hCapturedFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR_TEXTENCODE m_textFIR = new NBioAPI.Type.FIR_TEXTENCODE(); NBioAPI.Type.FIR_PAYLOAD myPayload = new NBioAPI.Type.FIR_PAYLOAD(); m_textFIR.TextFIR = Digital.ToString(); m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); m_NBioAPI.Capture(out hCapturedFIR); ret = m_NBioAPI.VerifyMatch(hCapturedFIR, m_textFIR, out result, myPayload); if (result == true) { return("OK"); } else { return(""); } }
//recebe HFIR e retorna TEXTENCODE public NBioAPI.Type.FIR_TEXTENCODE Fir_to_TextEncode(NBioAPI.Type.HFIR hfir) { NBioAPI.Type.FIR_TEXTENCODE txtencode = new NBioAPI.Type.FIR_TEXTENCODE(); m_NBioAPI.GetTextFIRFromHandle(hfir, out txtencode, true); return(txtencode); }
//recebe HFIR retorna Bitmap public Bitmap Conversor(NBioAPI.Type.HFIR Fir_toImage) { NBioAPI.Export.EXPORT_AUDIT_DATA exportData; m_Export.NBioBSPToImage(Fir_toImage, out exportData); int nWidth = (int)exportData.ImageWidth; int nHeight = (int)exportData.ImageHeight; { // bmp image save... bmp = new Bitmap(nWidth, nHeight, PixelFormat.Format8bppIndexed); BitmapData data = bmp.LockBits(new Rectangle(0, 0, nWidth, nHeight), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); System.Runtime.InteropServices.Marshal.Copy(exportData.AuditData[0].Image[0].Data, 0, data.Scan0, nWidth * nHeight); bmp.UnlockBits(data); ColorPalette GrayscalePalette = bmp.Palette; for (int i = 0; i < 256; i++) { GrayscalePalette.Entries[i] = Color.FromArgb(i, i, i); } bmp.Palette = GrayscalePalette; // bmp.Save("RollImage.bmp"); } //Image img = bmp; return(bmp); }
public String CapturarDigitaisParaInscricao() { try { NBioAPI.Type.HFIR template = new NBioAPI.Type.HFIR(); uint retorno = api.Enroll(out template, null); if (retorno == NBioAPI.Error.NONE) { NBioAPI.Type.FIR_TEXTENCODE binario = new NBioAPI.Type.FIR_TEXTENCODE(); api.GetTextFIRFromHandle(template, out binario, false); return(binario.TextFIR); } else { Console.WriteLine(retorno); return(null); } } catch (Exception ex) { throw new Exception("Erro ao capturar as digitais.", ex); } }
public Task <int> CriarTaskParaIdentificacaoBiometrica(NBioAPI.Type.HFIR template) { var contextoIdentificacao = new ContextoParaIndentificacaoBiometrica(Id, MecanismoBusca, template); CancellationSource = new CancellationTokenSource(); var token = CancellationSource.Token; return(new Task <int>((parametroState) => { var contexto = parametroState as ContextoParaIndentificacaoBiometrica; if (token.IsCancellationRequested) { return 0; } var cbInfo = new NBioAPI.IndexSearch.CALLBACK_INFO_0(); NBioAPI.IndexSearch.FP_INFO nitgenBiometria; var relogio = new Stopwatch(); relogio.Start(); var retorno = contexto.MecanismoBusca.IdentifyData(contexto.TemplateLido, NBioAPI.Type.FIR_SECURITY_LEVEL.HIGH, out nitgenBiometria, cbInfo); relogio.Stop(); Console.WriteLine($"{contexto.Id} - Localizado {nitgenBiometria.ID} em {relogio.Elapsed.TotalSeconds}"); if (token.IsCancellationRequested) { return 0; } return (int)nitgenBiometria.ID; }, contextoIdentificacao, token)); }
public string Enroll() { NBioAPI.Type.FIR_TEXTENCODE m_textFIR = new NBioAPI.Type.FIR_TEXTENCODE(); NBioAPI.Type.HFIR NewFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.WINDOW_OPTION m_WinOption = new NBioAPI.Type.WINDOW_OPTION(); m_WinOption.WindowStyle = (uint)NBioAPI.Type.WINDOW_STYLE.NO_WELCOME; string Retorno = ""; uint device = m_NBioAPI.OpenDevice(255); if (device != NBioAPI.Error.NONE) { return(null); } uint ret = m_NBioAPI.Enroll(out NewFIR, null); if (NewFIR != null) { m_NBioAPI.GetTextFIRFromHandle(NewFIR, out m_textFIR, true); if (m_textFIR.TextFIR != null) { m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); Retorno = m_textFIR.TextFIR.ToString(); } } m_NBioAPI.CloseDevice(255); return(Retorno); }
public int IdentificarBiometria(NBioAPI.Type.HFIR template) { var primeiraTask = true; var tasks = new Dictionary <Guid, Task <int> >(); foreach (var buscaNitgen in _mecanismosBusca) { // Se for a primeira task, adiciona as biometrias capturadas nos últimos momentos if (primeiraTask) { Console.WriteLine($"{buscaNitgen.Id} - Adicionando diferenças na Task que já possui {buscaNitgen.Biometrias.Count()} biometrias"); var diferenca = _repositorio.RecuperarDiferenca(_dataUltimaBusca); Console.WriteLine($"{buscaNitgen.Id} - {diferenca.Count()} diferenças encontradas..."); if (diferenca.Count() > 0) { buscaNitgen.AdicionarDiferencas(diferenca); Console.WriteLine($"{buscaNitgen.Id} - Diferenças adicionadas. Task com {buscaNitgen.Biometrias.Count()} biometrias..."); } _dataUltimaBusca = DateTime.Now; primeiraTask = false; } var task = buscaNitgen.CriarTaskParaIdentificacaoBiometrica(template, _mecanismoConfirmacao); tasks.Add(buscaNitgen.Id, task); if (!task.IsCanceled) { task.Start(); } } Console.WriteLine($"Localizado digital ..."); var relogio = new Stopwatch(); relogio.Start(); var biometriaEncontrada = 0; while (tasks.Count() > 0) { var indice = Task.WaitAny(tasks.Select(t => t.Value).ToArray()); var resultado = tasks.ElementAt(indice); Console.WriteLine($"{resultado.Key} - Terminou com {resultado.Value.Result} e foi {resultado.Value.Status}"); if (resultado.Value.Status == TaskStatus.RanToCompletion && resultado.Value.Result > 0) { foreach (var task in tasks.Where(t => t.Key != resultado.Key)) { _mecanismosBusca.FirstOrDefault(c => c.Id.Equals(task.Key)).CancellationSource.Cancel(); } relogio.Stop(); Console.WriteLine($"Localizada digital em > {relogio.Elapsed.TotalSeconds} segundos"); biometriaEncontrada = resultado.Value.Result; } tasks.Remove(resultado.Key); } relogio.Stop(); Console.WriteLine($"Nenhuma biometria encontrada em > {relogio.Elapsed.TotalSeconds} segundos"); return(biometriaEncontrada); }
private DigitalTask Create(NBioAPI.Type.HFIR template, IEnumerable <Biometria> biometrias) { var nitgenMainApi = new NBioAPI(); var nitgenSearchApi = new NBioAPI.IndexSearch(nitgenMainApi); nitgenSearchApi.InitEngine(); var nitgenConvertApi = new NBioAPI.Export(nitgenMainApi); var contextoIdentificacao = BiometriaIndentificacaoContexto.Novo(nitgenSearchApi, nitgenConvertApi); contextoIdentificacao.TemplateLido = template; var cancellationToken = new CancellationTokenSource(); var token = cancellationToken.Token; foreach (var biometria in biometrias) { NBioAPI.Type.HFIR handle; NBioAPI.IndexSearch.FP_INFO[] nitgenBiometria; nitgenConvertApi.FDxToNBioBSPEx(biometria.TemplateISO, (uint)biometria.TemplateISO.Length, NBioAPI.Type.MINCONV_DATA_TYPE.MINCONV_TYPE_ISO, NBioAPI.Type.FIR_PURPOSE.ENROLL_FOR_IDENTIFICATION_ONLY, out handle); nitgenSearchApi.AddFIR(handle, (uint)biometria.Id, out nitgenBiometria); } var task = new Task <int>((parametroState) => { var contexto = parametroState as BiometriaIndentificacaoContexto; Console.WriteLine($"{contexto.Id} - Iniciado "); if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } // Faz o Index Search var cbInfo = new NBioAPI.IndexSearch.CALLBACK_INFO_0(); NBioAPI.IndexSearch.FP_INFO nitgenBiometria; var relogio = new Stopwatch(); Console.WriteLine($"{contexto.Id} - Localizando biometria..."); relogio.Start(); var retorno = nitgenSearchApi.IdentifyData(contexto.TemplateLido, NBioAPI.Type.FIR_SECURITY_LEVEL.HIGH, out nitgenBiometria, cbInfo); relogio.Stop(); Console.WriteLine($"{contexto.Id} - Localizado {nitgenBiometria.ID} em {relogio.Elapsed.TotalSeconds}"); if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } Console.WriteLine($"{contexto.Id} - Finalizado "); return((int)nitgenBiometria.ID); }, contextoIdentificacao, token); return(new DigitalTask(contextoIdentificacao.Id, task, cancellationToken)); }
public ContextoParaIndentificacaoBiometrica(Guid id, NBioAPI mecanismoBusca, NBioAPI.IndexSearch mecanismoConfirmacao, NBioAPI.Export conversor, NBioAPI.Type.HFIR templateLido, IEnumerable <Biometria> biometrias) { Id = id; MecanismoBusca = mecanismoBusca; TemplateLido = templateLido; Biometrias = biometrias; MecanismoConfirmacao = mecanismoConfirmacao; Conversor = conversor; }
private void btnBiometria_Click(object sender, EventArgs e) { if (txtUsername.Text == "") { MessageBox.Show("Favor, preencher o campo de usuário", "Projeto Biometria", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtUsername.Focus(); } else { uint reta = m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); user = new User(); userC = new UserController(); user = userC.selectUser(txtUsername.Text); bool result; if (user != null) { NBioAPI.Type.HFIR bNewFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR m_biFIR = new NBioAPI.Type.FIR(); NBioAPI.Type.FIR_PAYLOAD myPayload = new NBioAPI.Type.FIR_PAYLOAD(); m_biFIR.Format = (uint)user.Format; m_biFIR.Data = user.Digital; m_biFIR.Header.DataLength = (uint)user.DataLength; m_biFIR.Header.DataType = (ushort)user.DataType; m_biFIR.Header.Length = (uint)user.Length; m_biFIR.Header.Purpose = (ushort)user.Purpose; m_biFIR.Header.Quality = (ushort)user.Quality; m_biFIR.Header.Reserved = (uint)user.Reserved; m_biFIR.Header.Version = (ushort)user.Version; uint ret = m_NBioAPI.Verify(m_biFIR, out result, myPayload); if (result) { MessageBox.Show("Verificação bem Sucedida!!", "Projeto Biometria", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); this.ShowIcon = false; this.ShowInTaskbar = false; frmMain main = new frmMain(user); main.ShowDialog(); this.ShowIcon = true; this.ShowInTaskbar = true; this.Show(); } else { MessageBox.Show("Verificação Incorreta! Tente novamente", "´Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); } }
private dynamic buscar(dynamic dados) { JObject objJson; //string url = "http://localhost:3200/api/biometrico"; //var json = new WebClient().DownloadString(url); // dynamic m = JsonConvert.DeserializeObject( dados ); uint ret; bool result; NBioAPI m_NBioAPI = new NBioAPI(); NBioAPI.Type.HFIR hCapturedFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR_TEXTENCODE m_textFIR = new NBioAPI.Type.FIR_TEXTENCODE(); NBioAPI.Type.FIR_PAYLOAD myPayload = new NBioAPI.Type.FIR_PAYLOAD(); //m_textFIR.TextFIR = Digital.ToString(); m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); m_NBioAPI.Capture(out hCapturedFIR); dynamic retorno = "-"; int idx = -1; int idxEncontrou = -1; foreach (dynamic obj in dados) { idx++; m_textFIR.TextFIR = obj.digital; ret = m_NBioAPI.VerifyMatch(hCapturedFIR, m_textFIR, out result, myPayload); if (result == true) { idxEncontrou = idx; break; } } if (idxEncontrou > -1) { string str1 = "{status: true, msg: 'Digital encontrada', indice: " + idxEncontrou + "}"; objJson = JObject.Parse(str1); return(objJson); } string str = "{status: false, msg: 'Digital não encontrada'}"; objJson = JObject.Parse(str); return(objJson); //return m; }
private void buttonAdv1_Click(object sender, EventArgs e) { LeitorBiometrico leitor = new LeitorBiometrico(); NBioAPI.Type.HFIR teste = leitor.Capturar(); NBioAPI.Type.FIR_TEXTENCODE teste2; NBioAPI m_NBioAPI = new NBioAPI(); m_NBioAPI.GetTextFIRFromHandle(teste, out teste2, true); string teste3 = teste2.TextFIR; MessageBox.Show(teste3); }
//Enroll public void CadastrarDigital() { NBioAPI.Type.FIR biFIR = null; NBioAPI.Type.HFIR newFIR = null; Inicializar(); uint ret = nBioApi.Enroll(out newFIR, null); if (ret == NBioAPI.Error.NONE) { nBioApi.GetFIRFromHandle(newFIR, out biFIR); } Finalizar(); }
public int IdentificarBiometria(NBioAPI.Type.HFIR template) { Console.WriteLine($"Localizado digital ..."); var cbInfo = new NBioAPI.IndexSearch.CALLBACK_INFO_0(); NBioAPI.IndexSearch.FP_INFO nitgenBiometria; var relogio = new Stopwatch(); relogio.Start(); var retorno = _nitgenSearchApi.IdentifyData(template, NBioAPI.Type.FIR_SECURITY_LEVEL.HIGH, out nitgenBiometria, cbInfo); relogio.Stop(); Console.WriteLine($"Localizado {nitgenBiometria.ID} em {relogio.Elapsed.TotalSeconds}"); return((int)nitgenBiometria.ID); }
public string CapturarDigitalParaVerificacao() { NBioAPI.Type.HFIR template = new NBioAPI.Type.HFIR(); uint retorno = api.Capture(out template); if (retorno == NBioAPI.Error.NONE) { NBioAPI.Type.FIR_TEXTENCODE binario = new NBioAPI.Type.FIR_TEXTENCODE(); api.GetTextFIRFromHandle(template, out binario, false); return(binario.TextFIR); } throw new Exception("Erro ao capturar a digital."); }
public Task <int> CriarTaskParaIdentificacaoBiometrica(NBioAPI.Type.HFIR template, IEnumerable <Biometria> biometrias) { var contextoIdentificacao = new ContextoParaIndentificacaoBiometrica(Id, biometrias, template); CancellationSource = new CancellationTokenSource(); var token = CancellationSource.Token; return(new Task <int>((parametroState) => { try { var contexto = parametroState as ContextoParaIndentificacaoBiometrica; if (token.IsCancellationRequested) { return 0; } var nitgenMainApi = new NBioAPI(); var nitgenSearchApi = new NBioAPI.IndexSearch(nitgenMainApi); nitgenSearchApi.InitEngine(); foreach (var biometria in contexto.Biometrias) { var biometriaNitgen = new NBioAPI.Type.FIR_TEXTENCODE { TextFIR = biometria.TemplateISOText }; NBioAPI.IndexSearch.FP_INFO[] informacaoBiometria; nitgenSearchApi.AddFIR(biometriaNitgen, (uint)biometria.Id, out informacaoBiometria); } var cbInfo = new NBioAPI.IndexSearch.CALLBACK_INFO_0(); cbInfo.CallBackFunction = new NBioAPI.IndexSearch.INDEXSEARCH_CALLBACK(Callback); NBioAPI.IndexSearch.FP_INFO nitgenBiometria; var relogio = new Stopwatch(); relogio.Start(); var retorno = nitgenSearchApi.IdentifyData(contexto.TemplateLido, NBioAPI.Type.FIR_SECURITY_LEVEL.HIGH, out nitgenBiometria, cbInfo); relogio.Stop(); Console.WriteLine($"{contexto.Id} - Localizado {nitgenBiometria.ID} em {relogio.Elapsed.TotalSeconds}"); return (int)nitgenBiometria.ID; } catch (Exception ex) { Console.WriteLine(ex.Message); return 0; } }, contextoIdentificacao, token)); }
private void Button1_Click(object sender, EventArgs e) { m_WinOption.WindowStyle = NBioAPI.Type.WINDOW_STYLE.INVISIBLE; retorno_para_exportar = new NBioAPI.Type.HFIR(); m_hNewFIR = new NBioAPI.Type.HFIR(); m_NBioAPI.OpenDevice(255); uint ret = m_NBioAPI.Capture(NBioAPI.Type.FIR_PURPOSE.VERIFY, out m_hNewFIR, -1, retorno_para_exportar, m_WinOption); m_NBioAPI.GetTextFIRFromHandle(m_hNewFIR, out m_textFIR, true); Console.WriteLine("texto com m_new1 " + m_textFIR.TextFIR); m_textFIR = null; m_NBioAPI.GetTextFIRFromHandle(retorno_para_exportar, out m_textFIR, true); Console.WriteLine("text com retorno com retorno_para_exportar " + m_textFIR.TextFIR); bmp = utils.Conversor(m_textFIR); ptb_fp.Image = bmp; }
public string Capturar() { NBioAPI m_NBioAPI = new NBioAPI(); NBioAPI.Type.HFIR hCapturedFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR_TEXTENCODE texto = new NBioAPI.Type.FIR_TEXTENCODE(); // Get FIR data m_NBioAPI.OpenDevice(255); m_NBioAPI.Capture(out hCapturedFIR); m_NBioAPI.GetTextFIRFromHandle(hCapturedFIR, out texto, true); return(texto.TextFIR); }
public string Capturar() { NBioAPI.Type.HFIR hCapturedFIR = new NBioAPI.Type.HFIR(); NBioAPI.Type.HFIR hCapturedFIRaudit = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR_TEXTENCODE texto = new NBioAPI.Type.FIR_TEXTENCODE(); //Get FIR data uint device = m_NBioAPI.OpenDevice(255); if (device != NBioAPI.Error.NONE) { return(null); } m_NBioAPI.Capture(NBioAPI.Type.FIR_PURPOSE.VERIFY, out hCapturedFIR, -1, hCapturedFIRaudit, null); m_NBioAPI.GetTextFIRFromHandle(hCapturedFIR, out texto, true); m_NBioAPI.CloseDevice(255); return(texto.TextFIR); }
public int IdentificarBiometriaV2(NBioAPI.Type.HFIR template) { var relogio = new Stopwatch(); relogio.Start(); Console.WriteLine($"Localizado digital ..."); var repositorio = new DigitaisRepositorio(); var tasks = new ConcurrentDictionary <Guid, Task <int> >(); var numeroTotalBiometrias = repositorio.RecuperarNumeroTotalBiometrias(); var biometriasPorPagina = (numeroTotalBiometrias / Environment.ProcessorCount) + 10; for (int pagina = 1; pagina <= Environment.ProcessorCount; pagina++) { var biometriasRecuperadas = repositorio.RecuperarPagina(pagina, biometriasPorPagina); var buscaNitgen = NitgenBiometriaTaskV2.Novo(biometriasRecuperadas); var task = buscaNitgen.CriarTaskParaIdentificacaoBiometrica(template, biometriasRecuperadas); tasks.TryAdd(buscaNitgen.Id, task); task.Start(); } var cancelation = new CancellationTokenSource(); Task.WaitAll(tasks.Select(t => t.Value).ToArray(), cancelation.Token); var resultado = tasks.FirstOrDefault(x => x.Value.Status == TaskStatus.RanToCompletion && x.Value.Result > 0); var biometria = resultado.Key == Guid.Empty ? 0 : resultado.Value.Result; foreach (var item in tasks) { item.Value.Dispose(); } relogio.Stop(); Console.WriteLine($"Localizado digital em > {relogio.Elapsed.TotalSeconds} segundos"); return(biometria); }
public Byte[] getfingerImage(NBioAPI.Type.HFIR Fir_toImage) { NBioAPI m_NBioAPI = new NBioAPI(); NBioAPI.Export.EXPORT_AUDIT_DATA exportData; NBioAPI.Export m_Export = new NBioAPI.Export(m_NBioAPI); m_Export.NBioBSPToImage(Fir_toImage, out exportData); Bitmap bmp; int nWidth = (int)exportData.ImageWidth; int nHeight = (int)exportData.ImageHeight; { // bmp image save... bmp = new Bitmap(nWidth, nHeight, PixelFormat.Format8bppIndexed); BitmapData data = bmp.LockBits(new Rectangle(0, 0, nWidth, nHeight), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); System.Runtime.InteropServices.Marshal.Copy(exportData.AuditData[0].Image[0].Data, 0, data.Scan0, nWidth * nHeight); bmp.UnlockBits(data); ColorPalette GrayscalePalette = bmp.Palette; for (int i = 0; i < 256; i++) { GrayscalePalette.Entries[i] = Color.FromArgb(i, i, i); } bmp.Palette = GrayscalePalette; // bmp.Save("RollImage.bmp"); } //Image img = bmp; MemoryStream stream = new MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); Byte[] bytes = stream.ToArray(); return(bytes); }
public Byte[] Capturar(int id) { NBioAPI m_NBioAPI = new NBioAPI(); NBioAPI.Type.INIT_INFO_0 initInfo0; uint ret = m_NBioAPI.GetInitInfo(out initInfo0); Console.WriteLine("passeiaqui"); if (ret == NBioAPI.Error.NONE) { initInfo0.EnrollImageQuality = Convert.ToUInt32(50); initInfo0.VerifyImageQuality = Convert.ToUInt32(30); initInfo0.DefaultTimeout = Convert.ToUInt32(10000); initInfo0.SecurityLevel = (int)NBioAPI.Type.FIR_SECURITY_LEVEL.NORMAL - 1; } NBioAPI.IndexSearch m_IndexSearch = new NBioAPI.IndexSearch(m_NBioAPI); NBioAPI.Type.HFIR hCapturedFIR; NBioAPI.Type.HFIR AuditData = new NBioAPI.Type.HFIR(); NBioAPI.Type.FIR_TEXTENCODE texto; // Get FIR data m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); m_NBioAPI.Capture(NBioAPI.Type.FIR_PURPOSE.DENTIFY, out hCapturedFIR, -1, AuditData, null); //Console.WriteLine(Encoding.Default.GetString(getfingerImage(AuditData))); try { if (hCapturedFIR != null) { return(getfingerImage(AuditData)); } return(null); } catch (Exception ex) { throw new Exception("ERRO:... " + ex.Message); } }
private void ISOV1_Click(object sender, EventArgs e) { string szTemp; listRet.Items.Clear(); listRet.Items.Add("OpenDevice start..."); uint nRet = m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Type.HFIR hFIR, hAuditFIR; hAuditFIR = new NBioAPI.Type.HFIR(); listRet.Items.Add("Enroll start..."); m_NBioAPI.Enroll(null, out hFIR, null, NBioAPI.Type.TIMEOUT.DEFAULT, hAuditFIR, null); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Export.EXPORT_AUDIT_DATA exportData; listRet.Items.Add("NBioBSPToImage start..."); nRet = m_Export.NBioBSPToImage(hAuditFIR, out exportData); if (nRet == NBioAPI.Error.NONE) { byte[] ISOBuf; listRet.Items.Add("ExportRawToISOV1 start..."); nRet = NBioBSPISO4.ExportRawToISOV1(exportData, false, NBioBSPISO4.COMPRESS_MOD.NONE, out ISOBuf); if (nRet == NBioAPI.Error.NONE) { NBioBSPISO4.NIMPORTRAWSET ImportRawSet; listRet.Items.Add("ImportISOToRaw start..."); nRet = NBioBSPISO4.ImportISOToRaw(ISOBuf, out ImportRawSet); if (nRet == NBioAPI.Error.NONE) { listRet.Items.Add("Test result"); for (byte i = 0; i < ImportRawSet.nDataCount; i++) { szTemp = "DataLen: " + ImportRawSet.ImportRawData[i].RawData.Length; listRet.Items.Add(szTemp); szTemp = "FingerID: " + ImportRawSet.ImportRawData[i].nFingerID; listRet.Items.Add(szTemp); szTemp = "Image Width: " + ImportRawSet.ImportRawData[i].nImgWidth; listRet.Items.Add(szTemp); szTemp = "Image Height: " + ImportRawSet.ImportRawData[i].nImgHeight; listRet.Items.Add(szTemp); } } else { szTemp = "ImportISOToRaw Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "ExportRawToISOV1 Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "NBioBSPToImage Error: " + nRet; listRet.Items.Add(szTemp); } hFIR.Dispose(); hAuditFIR.Dispose(); } else { szTemp = "Enroll Error: " + nRet; listRet.Items.Add(szTemp); } m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); } else { szTemp = "CloseDevice Error: " + nRet; listRet.Items.Add(szTemp); } }
public Task <int> CriarTaskParaIdentificacaoBiometrica(NBioAPI.Type.HFIR template, NBioAPI.IndexSearch mecanismoConfirmacao) { var contextoIdentificacao = new ContextoParaIndentificacaoBiometrica(Id, MecanismoBusca, mecanismoConfirmacao, Conversor, template, Biometrias); CancellationSource = new CancellationTokenSource(); var token = CancellationSource.Token; return(new Task <int>((parametroState) => { var contexto = parametroState as ContextoParaIndentificacaoBiometrica; if (token.IsCancellationRequested) { return 0; } var encontrou = false; var relogio = new Stopwatch(); relogio.Start(); foreach (var biometria in contexto.Biometrias) { if (token.IsCancellationRequested) { relogio.Stop(); Console.WriteLine($"{contexto.Id} - cancelado pois encontrado em outra thread {relogio.Elapsed.TotalSeconds}"); return 0; } var payload = new NBioAPI.Type.FIR_PAYLOAD(); NBioAPI.Type.HFIR handler; contexto.Conversor.FDxToNBioBSPEx(biometria.TemplateISO, (uint)biometria.TemplateISO.Length, NBioAPI.Type.MINCONV_DATA_TYPE.MINCONV_TYPE_ISO, NBioAPI.Type.FIR_PURPOSE.ENROLL_FOR_IDENTIFICATION_ONLY, out handler); var retorno = contexto.MecanismoBusca.VerifyMatch(contexto.TemplateLido, handler, out encontrou, payload); if (encontrou) { contexto.MecanismoConfirmacao.InitEngine(); NBioAPI.IndexSearch.FP_INFO[] informacaoBiometria; var ret = contexto.MecanismoConfirmacao.AddFIR(handler, (uint)biometria.Id, out informacaoBiometria); var cbInfo = new NBioAPI.IndexSearch.CALLBACK_INFO_0(); NBioAPI.IndexSearch.FP_INFO nitgenBiometria; retorno = contexto.MecanismoConfirmacao.IdentifyData(contexto.TemplateLido, NBioAPI.Type.FIR_SECURITY_LEVEL.HIGH, out nitgenBiometria, cbInfo); var idEncontrado = nitgenBiometria.ID; contexto.MecanismoConfirmacao.RemoveUser((uint)biometria.Id); if (idEncontrado > 0) { relogio.Stop(); Console.WriteLine($"{contexto.Id} - Localizado {biometria.Id} em {relogio.Elapsed.TotalSeconds}"); return (int)idEncontrado; } } } relogio.Stop(); Console.WriteLine($"{contexto.Id} - Nenhuma biometria encontrada em {relogio.Elapsed.TotalSeconds}"); return 0; }, contextoIdentificacao, token)); }
private uint MakeFIRFromRawSet(NBioBSPISO4.NIMPORTRAWSET RawSet, out NBioAPI.Type.HFIR hProcessedFIR) { hProcessedFIR = null; if (RawSet.nDataCount < 1) { return(NBioAPI.Error.FUNCTION_FAIL); } uint nRet; int i, j, k; ushort nWidth = RawSet.ImportRawData[0].nImgWidth; ushort nHeight = RawSet.ImportRawData[0].nImgHeight; const int FINGER_ID_MAX = 11; byte[] arSampleCnt = new byte[FINGER_ID_MAX]; byte nSampleCnt = 0; string szTemp; listRet.Items.Add("NITGEN FIR creation start..."); for (i = 0; i < FINGER_ID_MAX; i++) { arSampleCnt[i] = 0; } // Image size check for (i = 0; i < RawSet.nDataCount; i++) { if (nWidth != RawSet.ImportRawData[i].nImgWidth || nHeight != RawSet.ImportRawData[i].nImgHeight) { return(NBioAPI.Error.FUNCTION_FAIL); } arSampleCnt[RawSet.ImportRawData[i].nFingerID]++; } // Sample per finger check for (i = 0; i < FINGER_ID_MAX; i++) { if (nSampleCnt == 0) { nSampleCnt = arSampleCnt[i]; } else { if (arSampleCnt[i] != 0 && nSampleCnt != arSampleCnt[i]) { return(NBioAPI.Error.FUNCTION_FAIL); } } } if (nSampleCnt < 1 || nSampleCnt > 2) { return(NBioAPI.Error.FUNCTION_FAIL); } // Make NBioAPI_EXPORT_AUDIT_DATA NBioAPI.Export.EXPORT_AUDIT_DATA exportAuditData; exportAuditData = new NBioAPI.Export.EXPORT_AUDIT_DATA(); exportAuditData.FingerNum = (byte)(RawSet.nDataCount / nSampleCnt); exportAuditData.SamplesPerFinger = nSampleCnt; exportAuditData.ImageWidth = nWidth; exportAuditData.ImageHeight = nHeight; exportAuditData.AuditData = new NBioAPI.Export.AUDIT_DATA[exportAuditData.FingerNum]; for (i = 0; i < exportAuditData.FingerNum; i++) { exportAuditData.AuditData[i].Image = new NBioAPI.Export.IMAGE_DATA[exportAuditData.SamplesPerFinger]; for (j = 0; j < FINGER_ID_MAX; j++) { if (arSampleCnt[j] != 0) { exportAuditData.AuditData[i].FingerID = (byte)j; arSampleCnt[j] = 0; break; } } for (j = 0, k = 0; j < RawSet.nDataCount; j++) { if (exportAuditData.AuditData[i].FingerID == RawSet.ImportRawData[j].nFingerID) { exportAuditData.AuditData[i].Image[k].Data = new byte[RawSet.ImportRawData[j].RawData.Length]; exportAuditData.AuditData[i].Image[k++].Data = RawSet.ImportRawData[j].RawData; } } } // Make Image handle NBioAPI.Type.HFIR hAuditFIR; nRet = m_Export.ImageToNBioBSP(exportAuditData, out hAuditFIR); if (nRet == NBioAPI.Error.NONE) { // Make FIR handle nRet = m_NBioAPI.Process(hAuditFIR, out hProcessedFIR); if (nRet != NBioAPI.Error.NONE) { szTemp = "Process Error: " + nRet; listRet.Items.Add(szTemp); } hAuditFIR.Dispose(); } else { szTemp = "ImageToNBioBSP Error: " + nRet; listRet.Items.Add(szTemp); } return(nRet); }
private uint MakeISO4Data(out byte[] ISOBuf) { string szTemp; listRet.Items.Add("ISO 19794-4 Data creation start..."); listRet.Items.Add("OpenDevice start..."); ISOBuf = null; uint nRet = m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Type.HFIR hFIR, hAuditData; hAuditData = new NBioAPI.Type.HFIR(); nRet = m_NBioAPI.Enroll(null, out hFIR, null, NBioAPI.Type.TIMEOUT.DEFAULT, hAuditData, null); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Export.EXPORT_AUDIT_DATA exportAuditData; nRet = m_Export.NBioBSPToImage(hAuditData, out exportAuditData); if (nRet == NBioAPI.Error.NONE) { nRet = NBioBSPISO4.ExportRawToISOV1(exportAuditData, false, NBioBSPISO4.COMPRESS_MOD.NONE, out ISOBuf); if (nRet == NBioAPI.Error.NONE) { szTemp = "ISO 19794-4 Data Len: " + ISOBuf.Length; listRet.Items.Add(szTemp); } else { szTemp = "ExportRawToISOV1 Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "NBioBSPToImage Error: " + nRet; listRet.Items.Add(szTemp); } hFIR.Dispose(); hAuditData.Dispose(); } else { szTemp = "Enroll Error: " + nRet; listRet.Items.Add(szTemp); } m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); } else { szTemp = "OpenDevice Error: " + nRet; listRet.Items.Add(szTemp); } return(nRet); }
private void ISOV2_Click(object sender, EventArgs e) { string szTemp; listRet.Items.Clear(); listRet.Items.Add("OpenDevice start..."); uint nRet = m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Type.HFIR hFIR, hAuditFIR; hAuditFIR = new NBioAPI.Type.HFIR(); listRet.Items.Add("Enroll start..."); m_NBioAPI.Capture(NBioAPI.Type.FIR_PURPOSE.VERIFY, out hFIR, NBioAPI.Type.TIMEOUT.DEFAULT, hAuditFIR, null); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Export.EXPORT_AUDIT_DATA exportData; listRet.Items.Add("NBioBSPToImage start..."); nRet = m_Export.NBioBSPToImage(hAuditFIR, out exportData); if (nRet == NBioAPI.Error.NONE) { byte[] ISOBuf; listRet.Items.Add("ExportRawToISOV2 start..."); nRet = NBioBSPISO4.ExportRawToISOV2((byte)NBioAPI.Type.FINGER_ID.LEFT_INDEX, (ushort)exportData.ImageWidth, (ushort)exportData.ImageHeight, exportData.AuditData[0].Image[0].Data, false, NBioBSPISO4.COMPRESS_MOD.NONE, out ISOBuf); if (nRet == NBioAPI.Error.NONE) { NBioBSPISO4.NIMPORTRAWSET ImportRawSet; listRet.Items.Add("ImportISOToRaw start..."); nRet = NBioBSPISO4.ImportISOToRaw(ISOBuf, out ImportRawSet); if (nRet == NBioAPI.Error.NONE) { listRet.Items.Add("Test result"); for (byte i = 0; i < ImportRawSet.nDataCount; i++) { szTemp = "DataLen: " + ImportRawSet.ImportRawData[i].RawData.Length; listRet.Items.Add(szTemp); szTemp = "FingerID: " + ImportRawSet.ImportRawData[i].nFingerID; listRet.Items.Add(szTemp); szTemp = "Image Width: " + ImportRawSet.ImportRawData[i].nImgWidth; listRet.Items.Add(szTemp); szTemp = "Image Height: " + ImportRawSet.ImportRawData[i].nImgHeight; listRet.Items.Add(szTemp); } } else { szTemp = "ImportISOToRaw Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "ExportRawToISOV2 Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "NBioBSPToImage Error: " + nRet; listRet.Items.Add(szTemp); } hFIR.Dispose(); hAuditFIR.Dispose(); } else { szTemp = "Capture Error: " + nRet; listRet.Items.Add(szTemp); } m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); } else { szTemp = "CloseDevice Error: " + nRet; listRet.Items.Add(szTemp); } }
private uint MakeISO4Data(out byte[] ISOBuf) { string szTemp; listRet.Items.Add("ISO 19794-4 Data creation start..."); listRet.Items.Add("OpenDevice start..."); ISOBuf = null; uint nRet = m_NBioAPI.OpenDevice(NBioAPI.Type.DEVICE_ID.AUTO); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Type.HFIR hFIR, hAuditData; hAuditData = new NBioAPI.Type.HFIR(); nRet = m_NBioAPI.Enroll(null, out hFIR, null, NBioAPI.Type.TIMEOUT.DEFAULT, hAuditData, null); if (nRet == NBioAPI.Error.NONE) { NBioAPI.Export.EXPORT_AUDIT_DATA exportAuditData; nRet = m_Export.NBioBSPToImage(hAuditData, out exportAuditData); if (nRet == NBioAPI.Error.NONE) { nRet = NBioBSPISO4.ExportRawToISOV1(exportAuditData, false, NBioBSPISO4.COMPRESS_MOD.NONE, out ISOBuf); if (nRet == NBioAPI.Error.NONE) { szTemp = "ISO 19794-4 Data Len: " + ISOBuf.Length; listRet.Items.Add(szTemp); } else { szTemp = "ExportRawToISOV1 Error: " + nRet; listRet.Items.Add(szTemp); } } else { szTemp = "NBioBSPToImage Error: " + nRet; listRet.Items.Add(szTemp); } hFIR.Dispose(); hAuditData.Dispose(); } else { szTemp = "Enroll Error: " + nRet; listRet.Items.Add(szTemp); } m_NBioAPI.CloseDevice(NBioAPI.Type.DEVICE_ID.AUTO); } else { szTemp = "OpenDevice Error: " + nRet; listRet.Items.Add(szTemp); } return nRet; }
public ContextoParaIndentificacaoBiometrica(Guid id, NBioAPI.IndexSearch mecanismoBusca, NBioAPI.Type.HFIR templateLido) { Id = id; MecanismoBusca = mecanismoBusca; TemplateLido = templateLido; }
public int IdentificarBiometria(NBioAPI.Type.HFIR template) { var tasks = new Dictionary <Guid, Task <int> >(); foreach (var buscaNitgen in _mecanismosBusca) { var task = buscaNitgen.CriarTaskParaIdentificacaoBiometrica(template); tasks.Add(buscaNitgen.Id, task); if (!task.IsCanceled) { task.Start(); } } Console.WriteLine($"Localizado digital ..."); var relogio = new Stopwatch(); relogio.Start(); var possoSair = false; //KeyValuePair<Guid, Task<int>> resultado = new KeyValuePair<Guid, Task<int>>(Guid.Empty, null); var cancelation = new CancellationTokenSource(); //Task.WaitAll(tasks.Select(t => t.Value).ToArray(), cancelation.Token); //var resultado = tasks.FirstOrDefault(x => x.Value.Status == TaskStatus.RanToCompletion && x.Value.Result > 0); while (tasks.Count() > 0) { var indice = Task.WaitAny(tasks.Select(t => t.Value).ToArray()); var resultado = tasks.ElementAt(indice); Console.WriteLine($"{resultado.Key} - Terminou com {resultado.Value.Result}"); if (resultado.Value.Result > 0) { relogio.Stop(); Console.WriteLine($"Localizada digital em > {relogio.Elapsed.TotalSeconds} segundos"); return(resultado.Value.Result); } tasks.Remove(resultado.Key); } relogio.Stop(); Console.WriteLine($"Localizado digital em > {relogio.Elapsed.TotalSeconds} segundos"); return(0); //while (!possoSair) //{ // if (tasks.Any(t => t.Value.IsCompleted)) // { // var completadas = tasks.Where(t => t.Value.IsCompleted && !t.Value.IsCanceled); // resultado = completadas.FirstOrDefault(c => c.Value.Result > 0); // if (resultado.Key != Guid.Empty) // { // foreach (var task in tasks.Where(t => t.Key != resultado.Key)) // _mecanismosBusca.FirstOrDefault(m => m.Id.Equals(task.Key)).CancellationSource.Cancel(); // possoSair = true; // } // } // if (tasks.All(t => t.Value.IsCompleted)) // possoSair = true; // Thread.Sleep(10); //} //relogio.Stop(); //Console.WriteLine($"Localizado digital em > {relogio.Elapsed.TotalSeconds} segundos"); //return resultado.Key == Guid.Empty // ? 0 // : resultado.Value.Result; }
public ContextoParaIndentificacaoBiometrica(Guid id, IEnumerable <Biometria> biometrias, NBioAPI.Type.HFIR templateLido) { Id = id; Biometrias = biometrias; TemplateLido = templateLido; }