private void captureProcess(int captureResult) { #region captureProcess if (captureResult == RS_SDK.RS_SUCCESS) { MsgPanel.Text = "Captura terminada"; SaveSeqCheckTargetProcess(capturedImageData, capturedImageWidth, capturedImageHeight); TakeAuto.Enabled = true; } else { RS_SDK.RS_GetErrString(captureResult, ref m_errorMsg); //MsgPanel.Text = m_errorMsg; MsgPanel.Text = "Huellas no detectadas"; MessageBox.Show("Baja calidad o dedo faltante, capture de nuevo.", "Aviso"); TakeAuto.Enabled = true; return; } int numOfFingers = 0; IntPtr[] ImageBuffer = new IntPtr[4]; int[] ImageWidth = new int[4]; int[] ImageHeight = new int[4]; RSSlapInfoArray slapInfoA = new RSSlapInfoArray(); if (SegmentCaptureProcess(capturedImageData, capturedImageWidth, capturedImageHeight, deviceHandle, ref slapInfoA, ref numOfFingers, ref ImageBuffer, ref ImageWidth, ref ImageHeight) == false) { if (capturedImageData != (IntPtr)0) { RS_SDK.RS_FreeImageData(capturedImageData); } return; } SegmentSaveImageCaptureProcess(capturedImageData, capturedImageWidth, capturedImageHeight, numOfFingers, slapInfoA, ImageBuffer, ImageWidth, ImageHeight); for (int i = 0; i < 4; i++) { if (ImageBuffer[i] != (IntPtr)0) { RS_SDK.RS_FreeImageData(ImageBuffer[i]); } } if (capturedImageData != (IntPtr)0) { RS_SDK.RS_FreeImageData(capturedImageData); } Close(); #endregion }
private void SegmentSaveImageCaptureProcess(IntPtr imageData, int imageWidth, int imageHeight, int numOfFingers, RSSlapInfoArray slapInfo, IntPtr[] ImageBuffer, int[] ImageWidth, int[] ImageHeight) { #region SegmentSaveImageCaptureProcess string bmp; string wsq; int dedo = 0; int result; int n = 0; byte[] huella = null; byte[] template = null; byte[] archivoWSQMem = null; int[] dedoPerdido = new int[] { 0, 0, 0, 0 }; int[] pulgarPerdido = new int[] { 0, 0 }; string palma; try { #region genera arreglo para identificar dedo sin huella switch (param[0]) { case "3": //PULGARES for (int i = 0; i < 2; i++) { if (clbPulgar.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[0] = 0; break; case 1: dedoPerdido[1] = 0; break; break; } } else { switch (i) { case 0: dedoPerdido[0] = 6; break; case 1: dedoPerdido[1] = 1; break; } } } break; case "4": //4 DEDOS MANO IZQUIERDA for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[0] = 0; break; case 1: dedoPerdido[1] = 0; break; case 2: dedoPerdido[2] = 0; break; case 3: dedoPerdido[3] = 0; break; } } else { switch (i) { case 0: dedoPerdido[0] = 10; break; case 1: dedoPerdido[1] = 9; break; case 2: dedoPerdido[2] = 8; break; case 3: dedoPerdido[3] = 7; break; } } } break; case "5": //4 DEDOS MANO DERECHA for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[3] = 0; break; case 1: dedoPerdido[2] = 0; break; case 2: dedoPerdido[1] = 0; break; case 3: dedoPerdido[0] = 0; break; } } else { switch (i) { case 0: dedoPerdido[3] = 5; break; case 1: dedoPerdido[2] = 4; break; case 2: dedoPerdido[1] = 3; break; case 3: dedoPerdido[0] = 2; break; } } } break; default: break; } #endregion #region codigo comentado //GENERA BMP DE LAS 4 HUELLAS //palma = param[1] + "palma_" + param[0] + ".bmp"; //RS_SDK.RS_SaveBitmap(imageData, imageWidth, imageHeight, palma); //if (m_result != RS_SDK.RS_SUCCESS) //{ // RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); // MsgPanel.Text = m_errorMsg; //} #endregion //me conecto a la base de datos conn = new OracleConnection(Conexion(param[3])); conn.Open(); //ciclo que recorre el arreglo de huellas for (int i = 0; i < numOfFingers; i++) { //identifico el id del dedo que se le asignara a la huella dedo = 0; while (dedo == 0) { dedo = dedoPerdido[n]; n++; } //genero el nombre de los archivos y su ruta bmp = param[1] + param[2] + "_" + dedo + ".bmp"; wsq = param[1] + param[2] + "_" + dedo + ".wsq"; //genero imagen de la huella result = RS_SDK.RS_SaveBitmap(ImageBuffer[i], ImageWidth[i], ImageHeight[i], bmp); //cargo ewn memoria el archivo de la huella FileStream fs = new FileStream(bmp, FileMode.Open, FileAccess.Read); huella = new byte[fs.Length]; fs.Read(huella, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); #region CODIGO DE PREUEBAS //result = RealScanExtendSDK.RSE_SaveRAW(ImageBuffer[i], ImageWidth[i], ImageHeight[i], "C:\\Temp\\huellas\\huella."+ "_" + dedo +"dat"); //creo el template... //template = new byte[ImageWidth[i] * ImageHeight[i]]; //Marshal.Copy(ImageBuffer[i], template, 0, ImageWidth[i] * ImageHeight[i]); #endregion //genero el archivo wsq RealScanExtendSDK.RSE_CompressWSQ(bmp, null, 3, wsq); //cargo en memoria el archivo wsq FileStream archivoWSQ = new FileStream(wsq, FileMode.Open, FileAccess.Read); archivoWSQMem = new byte[archivoWSQ.Length]; archivoWSQ.Read(archivoWSQMem, 0, System.Convert.ToInt32(archivoWSQ.Length)); archivoWSQ.Close(); //metodo que graba el registro en la base de datos RegistraHuella(dedo, huella, template, archivoWSQMem); //elimino los archivos del equipo File.Delete(bmp); File.Delete(wsq); } conn.Close(); conn.Dispose(); } catch (TargetInvocationException ex) { MsgPanel.Text = ex.Message; throw; } #endregion }
private bool SegmentCaptureProcess(IntPtr imageData, int imageWidth, int imageHeight, int deviceHandle, ref RSSlapInfoArray slapInfo, ref int numOfFingers, ref IntPtr[] ImageBuffer, ref int[] ImageWidth, ref int[] ImageHeight) { #region SegmentCaptureProcess RSSlapInfoArray slapInfoA = new RSSlapInfoArray(); IntPtr slapInfoArray; int captureMode = 0; int captureOption = 0; int slapType = 1; for (int i = 0; i < 4; i++) { ImageBuffer[i] = (IntPtr)0; ImageWidth[i] = 0; ImageHeight[i] = 0; } int _size = Marshal.SizeOf(typeof(RSSlapInfoArray)); slapInfoArray = Marshal.AllocHGlobal(_size); Marshal.StructureToPtr(slapInfoA, slapInfoArray, true); int fingerType = 0; int[] missingFingerArray = new int[] { 0, 0, 0, 0 }; int n = 0; //if (m_captureDir != RS_SDK.RS_CAPTURE_DIRECTION_DEFAULT) //{ // int captureDir = RS_SDK.RS_CAPTURE_DIRECTION_DEFAULT; // m_result = RS_SDK.RS_GetCaptureModeWithDir(deviceHandle, ref captureMode, ref captureDir, ref captureOption); //} //else m_result = RS_SDK.RS_GetCaptureMode(deviceHandle, ref captureMode, ref captureOption); if (m_result != RS_SDK.RS_SUCCESS) { RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); MsgPanel.Text = m_errorMsg; } switch (captureMode) { case RS_SDK.RS_CAPTURE_FLAT_TWO_FINGERS: case RS_SDK.RS_CAPTURE_FLAT_TWO_FINGERS_EX: slapType = RS_SDK.RS_SLAP_TWO_FINGER; break; case RS_SDK.RS_CAPTURE_FLAT_SINGLE_FINGER: case RS_SDK.RS_CAPTURE_FLAT_SINGLE_FINGER_EX: slapType = RS_SDK.RS_SLAP_ONE_FINGER; break; case RS_SDK.RS_CAPTURE_FLAT_LEFT_FOUR_FINGERS: slapType = RS_SDK.RS_SLAP_LEFT_FOUR; for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { missingFingerArray[n++] = RS_SDK.RS_FGP_LEFT_LITTLE - i; } } fingerType = RS_SDK.RS_FGP_LEFT_LITTLE; break; case RS_SDK.RS_CAPTURE_FLAT_RIGHT_FOUR_FINGERS: slapType = RS_SDK.RS_SLAP_RIGHT_FOUR; for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { missingFingerArray[n++] = i + RS_SDK.RS_FGP_RIGHT_INDEX; } } fingerType = RS_SDK.RS_FGP_RIGHT_INDEX; break; default: MsgPanel.Text = "Cannot segment in this mode"; return(false); } m_result = RS_SDK.RS_Segment4(imageData, imageWidth, imageHeight, slapType, ref numOfFingers, ref slapInfoArray, ref ImageBuffer[0], ref ImageWidth[0], ref ImageHeight[0], ref ImageBuffer[1], ref ImageWidth[1], ref ImageHeight[1], ref ImageBuffer[2], ref ImageWidth[2], ref ImageHeight[2], ref ImageBuffer[3], ref ImageWidth[3], ref ImageHeight[3]); if (m_result != RS_SDK.RS_SUCCESS) { if (m_result == RS_SDK.RS_ERR_SEGMENT_FEWER_FINGER) { if (m_minCount != numOfFingers) { RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); MsgPanel.Text = m_errorMsg; return(false); } } else { RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); MsgPanel.Text = m_errorMsg; return(false); } } MsgPanel.Text = "Calidad:"; slapInfoA = (RSSlapInfoArray)Marshal.PtrToStructure(slapInfoArray, typeof(RSSlapInfoArray)); if (slapInfoArray != (IntPtr)0) { RS_SDK.RS_FreeImageData(slapInfoArray); } int overlayHandle = -1; int j = 0; for (int i = 0; i < numOfFingers; i++) { if (slapInfoA.RSSlapInfoA[i].fingerType == RS_SDK.RS_FGP_UNKNOWN) { if (slapType == RS_SDK.RS_SLAP_LEFT_FOUR) { while (fingerType == missingFingerArray[j]) { fingerType--; j++; } slapInfoA.RSSlapInfoA[i].fingerType = fingerType--; } else if (slapType == RS_SDK.RS_SLAP_RIGHT_FOUR) { while (fingerType == missingFingerArray[j]) { fingerType++; j++; } slapInfoA.RSSlapInfoA[i].fingerType = fingerType++; } } slapInfo = slapInfoA; Enrolar. RSOverlayQuadrangle quad = new RSOverlayQuadrangle(); quad.pos = new RSPoint[4]; quad.color = 0x00ff0000; RSRect rect = new RSRect(); RS_SDK.GetClientRect(PreviewWindow.Handle, ref rect); quad.pos[0].x = slapInfoA.RSSlapInfoA[i].fingerPosition[0].x * rect.right / imageWidth; quad.pos[0].y = slapInfoA.RSSlapInfoA[i].fingerPosition[0].y * rect.bottom / imageHeight; quad.pos[1].x = slapInfoA.RSSlapInfoA[i].fingerPosition[1].x * rect.right / imageWidth; quad.pos[1].y = slapInfoA.RSSlapInfoA[i].fingerPosition[1].y * rect.bottom / imageHeight; quad.pos[2].x = slapInfoA.RSSlapInfoA[i].fingerPosition[3].x * rect.right / imageWidth; quad.pos[2].y = slapInfoA.RSSlapInfoA[i].fingerPosition[3].y * rect.bottom / imageHeight; quad.pos[3].x = slapInfoA.RSSlapInfoA[i].fingerPosition[2].x * rect.right / imageWidth; quad.pos[3].y = slapInfoA.RSSlapInfoA[i].fingerPosition[2].y * rect.bottom / imageHeight; m_result = RS_SDK.RS_AddOverlayQuadrangle(deviceHandle, ref quad, ref overlayHandle); m_result = RS_SDK.RS_ShowOverlay(overlayHandle, true); if (m_result != RS_SDK.RS_SUCCESS) { MsgPanel.Text = "Cannot overlay for quadrangle" + m_result; return(false); } } for (int i = 0; i < numOfFingers; i++) { MsgPanel.Text += "[" + slapInfoA.RSSlapInfoA[i].fingerType + ":" + slapInfoA.RSSlapInfoA[i].imageQuality + "] "; } return(true); #endregion }
private void SegmentSaveImageCaptureProcess(IntPtr imageData, int imageWidth, int imageHeight, int numOfFingers, RSSlapInfoArray slapInfo, IntPtr[] ImageBuffer, int[] ImageWidth, int[] ImageHeight) { #region SegmentSaveImageCaptureProcess SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.InitialDirectory = ".:\\"; saveDialog.FilterIndex = 1; string bmp; string wsq; int result; byte[] huella = null; byte[] wsqBuffer = null; int dedo = 0; int tamano = 0; byte[] template = null; int[] dedoPerdido = new int[] { 0, 0, 0, 0 }; int[] pulgarPerdido = new int[] { 0, 0 }; int n = 0; try { #region genera arreglo para identificar dedo sin huella switch (param[0]) { case "3": //PULGARES for (int i = 0; i < 2; i++) { if (clbPulgar.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[0] = 0; break; case 1: dedoPerdido[1] = 0; break; break; } } else { switch (i) { case 0: dedoPerdido[0] = 6; break; case 1: dedoPerdido[1] = 1; break; } } } break; case "4": //4 DEDOS MANO IZQUIERDA for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[0] = 0; break; case 1: dedoPerdido[1] = 0; break; case 2: dedoPerdido[2] = 0; break; case 3: dedoPerdido[3] = 0; break; } } else { switch (i) { case 0: dedoPerdido[0] = 10; break; case 1: dedoPerdido[1] = 9; break; case 2: dedoPerdido[2] = 8; break; case 3: dedoPerdido[3] = 7; break; } } } break; case "5": //4 DEDOS MANO DERECHA for (int i = 0; i < 4; i++) { if (clbDedo.GetItemChecked(i)) { switch (i) { case 0: dedoPerdido[3] = 0; break; case 1: dedoPerdido[2] = 0; break; case 2: dedoPerdido[1] = 0; break; case 3: dedoPerdido[0] = 0; break; } } else { switch (i) { case 0: dedoPerdido[3] = 5; break; case 1: dedoPerdido[2] = 4; break; case 2: dedoPerdido[1] = 3; break; case 3: dedoPerdido[0] = 2; break; } } } break; default: break; } #endregion //RS_SDK.RS_SaveBitmap(imageData, imageWidth, imageHeight, param[1] + param[2] + ".bmp"); //if (m_result != RS_SDK.RS_SUCCESS) //{ // RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); // MsgPanel.Text = m_errorMsg; //} conn = new OracleConnection(Conexion(param[3])); conn.Open(); for (int i = 0; i < numOfFingers; i++) { dedo = 0; while (dedo == 0) { dedo = dedoPerdido[n]; n++; } bmp = param[1] + param[2] + "_" + dedo + ".bmp"; wsq = param[1] + param[2] + "_" + dedo + ".wsq"; result = RS_SDK.RS_SaveBitmap(ImageBuffer[i], ImageWidth[i], ImageHeight[i], bmp); //result = RS_SDK.RS_EncodeWSQ(ImageBuffer[i], ImageWidth[i], ImageHeight[i], 0.75, ref wsqBuffer, ref tamano); //result = RealScanExtendSDK.RSE_CompressWSQ(bmp, null, 0.75, wsq); FileStream fs = new FileStream(bmp, FileMode.Open, FileAccess.Read); huella = new byte[fs.Length]; fs.Read(huella, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); //result = RS_SDK.RS_SaveBitmapMem(ImageBuffer[i], ImageWidth[i], ImageHeight[i], huella); template = new byte[ImageWidth[i] * ImageHeight[i]]; Marshal.Copy(ImageBuffer[i], template, 0, ImageWidth[i] * ImageHeight[i]); RegistraHuella(dedo, huella, template); File.Delete(bmp); //result = RealScanExtendSDK.RSE_CompressWSQ(bmp, null, 2.25, wsq); //result = RealScanExtendSDK.RSE_CompressWSQBuffer(bmp, null, 0.75, memwsq, tamano); if (m_result != RS_SDK.RS_SUCCESS) { RS_SDK.RS_GetErrString(m_result, ref m_errorMsg); MsgPanel.Text = m_errorMsg; } } conn.Close(); conn.Dispose(); } catch (Exception ex) { MsgPanel.Text = ex.Message; } #endregion }