예제 #1
0
 internal static extern int GetConfidenceLevel([In] IntPtr hRecAtls, [Out] out RECO_RANGE recoRange, [Out] out RecognitionConfidence confidenceLevel);
        //------------------------------------------------------------------------------- 
        //
        // Constructors 
        //
        //-------------------------------------------------------------------------------

        #region Constructors 

        internal GestureRecognitionResult(RecognitionConfidence confidence, ApplicationGesture gesture) 
        { 
            _confidence = confidence;
            _gesture = gesture; 
        }
예제 #3
0
        /// <summary>
        /// Invokes GetLatticePtr in the native dll
        /// </summary>
        /// <returns></returns>
        private GestureRecognitionResult[] InvokeGetLatticePtr()
        {
            GestureRecognitionResult[] recResults = new GestureRecognitionResult[] { };

//            int hr = 0;
            IntPtr ptr = IntPtr.Zero;

            // NOTICE-2005/07/11-WAYNEZEN,
            // There is no need to free the returned the structure.
            // The memory will be released when ResetContext, which is invoked in the callee - Recognize, is called.
            if (HRESULT.Succeeded(
                    MS.Win32.Recognizer.UnsafeNativeMethods.GetLatticePtr(
                        _hContext, ref ptr)))
            {
                unsafe
                {
                    MS.Win32.Recognizer.RECO_LATTICE *pRecoLattice = (MS.Win32.Recognizer.RECO_LATTICE *)ptr;

                    uint bestResultColumnCount = pRecoLattice->ulBestResultColumnCount;
                    Debug.Assert(!(bestResultColumnCount != 0 && pRecoLattice->pLatticeColumns == IntPtr.Zero), "Invalid results!");
                    if (bestResultColumnCount > 0 && pRecoLattice->pLatticeColumns != IntPtr.Zero)
                    {
                        List <GestureRecognitionResult> resultList = new List <GestureRecognitionResult>();

                        MS.Win32.Recognizer.RECO_LATTICE_COLUMN *pLatticeColumns =
                            (MS.Win32.Recognizer.RECO_LATTICE_COLUMN *)(pRecoLattice->pLatticeColumns);
                        ulong *pulBestResultColumns = (ulong *)(pRecoLattice->pulBestResultColumns);

                        for (uint i = 0; i < bestResultColumnCount; i++)
                        {
                            ulong column = pulBestResultColumns[i];
                            MS.Win32.Recognizer.RECO_LATTICE_COLUMN recoColumn = pLatticeColumns[column];

                            Debug.Assert(0 < recoColumn.cLatticeElements, "Invalid results!");

                            for (int j = 0; j < recoColumn.cLatticeElements; j++)
                            {
                                MS.Win32.Recognizer.RECO_LATTICE_ELEMENT recoElement =
                                    ((MS.Win32.Recognizer.RECO_LATTICE_ELEMENT *)(recoColumn.pLatticeElements))[j];

                                Debug.Assert((RECO_TYPE)(recoElement.type) == RECO_TYPE.RECO_TYPE_WCHAR, "The Application gesture has to be WCHAR type");

                                if ((RECO_TYPE)(recoElement.type) == RECO_TYPE.RECO_TYPE_WCHAR)
                                {
                                    // Retrieve the confidence lever
                                    RecognitionConfidence confidenceLevel = RecognitionConfidence.Poor;

                                    MS.Win32.Recognizer.RECO_LATTICE_PROPERTIES recoProperties = recoElement.epProp;

                                    uint propertyCount = recoProperties.cProperties;
                                    MS.Win32.Recognizer.RECO_LATTICE_PROPERTY **apProps =
                                        (MS.Win32.Recognizer.RECO_LATTICE_PROPERTY * *)recoProperties.apProps;
                                    for (int k = 0; k < propertyCount; k++)
                                    {
                                        MS.Win32.Recognizer.RECO_LATTICE_PROPERTY *pProps = apProps[k];
                                        if (pProps->guidProperty == GUID_CONFIDENCELEVEL)
                                        {
                                            Debug.Assert(pProps->cbPropertyValue == sizeof(uint) / sizeof(byte));
                                            RecognitionConfidence level = (RecognitionConfidence)(((uint *)pProps->pPropertyValue))[0];
                                            if (level >= RecognitionConfidence.Strong && level <= RecognitionConfidence.Poor)
                                            {
                                                confidenceLevel = level;
                                            }

                                            break;
                                        }
                                    }

                                    ApplicationGesture gesture = (ApplicationGesture)((char)(recoElement.pData));
                                    Debug.Assert(ApplicationGestureHelper.IsDefined(gesture));
                                    if (ApplicationGestureHelper.IsDefined(gesture))
                                    {
                                        // Get the gesture result
                                        resultList.Add(new GestureRecognitionResult(confidenceLevel, gesture));
                                    }
                                }
                            }
                        }

                        recResults = (GestureRecognitionResult[])(resultList.ToArray());
                    }
                }
            }

            return(recResults);
        }
        //-------------------------------------------------------------------------------
        //
        // Constructors
        //
        //-------------------------------------------------------------------------------

        #region Constructors

        internal GestureRecognitionResult(RecognitionConfidence confidence, ApplicationGesture gesture)
        {
            _confidence = confidence;
            _gesture    = gesture;
        }