Example #1
0
        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
        }