コード例 #1
0
        public override HiddenModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea(i, "S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            foreach (var symTrace in symbolTraces)
            {
                var prevT = symTrace[0].Time;
                for (int i = 1; i < symTrace.Length; i++)
                {
                    var dT = (int)(symTrace[i].Time - prevT);
                    prevT = symTrace[i].Time;
                    transitionDatas[i - 1].addData(dT);
                }
            }

            var   startState = new StartState();
            State curState   = startState;
            State nextState;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                var transition = transData.createTransition(nextState);
                curState.addTransition(transition);
                curState = nextState;
            }

            var model = new HiddenModel(startState, curState);

            return(model);
        }
コード例 #2
0
 public TrajectoryModel(CHnMMClassificationSystem system, string name, IEnumerable <BaseTrajectory> trainingData)
 {
     recognitionSystem = system;
     Name      = name;
     strokeMap = system.HiddenModelCreator.createStrokeMap(trainingData);
     model     = system.HiddenModelCreator.createModel(trainingData, strokeMap);
 }
コード例 #3
0
        public override CHnMModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea(i, "S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            foreach (var symTrace in symbolTraces)
            {
                if (symTrace != null)
                {
                    var has_empty = symTrace.Where(w => w == null).ToArray();
                    if (has_empty.Length == 0)
                    {
                        var symTrace_clean = symTrace.Where(w => w.Symbol != "GestureStart").ToArray();
                        var prevT          = symTrace[0].Time;
                        for (int i = 0; i < symTrace_clean.Length; i++)
                        {
                            var dT = (int)(symTrace_clean[i].Time - prevT);
                            prevT = symTrace_clean[i].Time;
                            transitionDatas[i].addData(dT);;
                        }
                    }
                    else
                    {
                        //handle the empty datas here
                    }
                }
            }

            var   startState = new StartState();
            State curState   = startState;
            State nextState;

            int ai = 0;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                var transition = transData.createTransition(nextState, strokeMap.Areas[ai++]);
                curState.addTransition(transition);
                curState = nextState;
            }

            var model = new CHnMModel(startState, curState);

            return(model);
        }
コード例 #4
0
        public override CHnMModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea("S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            ////number of areas -> transitiondata to endState
            //var endTransitions = new Dictionary<int,TransitionData>(15);

            var endTransitionData = transitionSetup.createTransitionDataToEnd();


            foreach (var symTrace in symbolTraces)
            {
                var prevT = symTrace[0].Time;             //GestureStart is dummy symbol marking the beginning
                for (int i = 1; i < symTrace.Length; i++) //go through all symbols of a trace (except GestureEnd)
                {
                    var dT = (int)(symTrace[i].Time - prevT);
                    prevT = symTrace[i].Time;

                    if (i == symTrace.Length - 1)
                    {
                        endTransitionData.addData(dT);
                        //TransitionData endTransition;
                        //if(endTransitions.TryGetValue(i, out endTransition))
                        //{
                        //    endTransition.addData(dT);
                        //}
                        //else
                        //{
                        //    Debug.Assert(symTrace[i].Symbol == "GestureEnd");
                        //    endTransition = transitionSetup.createTransitionDataToEnd(); //use endtransition
                        //    endTransition.addData(dT);
                        //    endTransitions[i] = endTransition;
                        //}
                    }
                    else
                    {
                        transitionDatas[i - 1].addData(dT);
                    }
                }
            }

            //var endTransPositions = endTransitions.Select(e => e.Key).OrderBy(x => x).ToArray();
            //Debug.Assert(endTransPositions.Last() - endTransPositions.First() == endTransitions.Count-1);

            var   startState = new StartState();
            var   areaStates = new State[strokeMap.Areas.Length];
            var   endState   = new State();
            State curState   = startState;
            State nextState;

            int curAreaState = 0;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                areaStates[curAreaState++] = nextState;
                var transition = transData.createTransition(nextState, null);
                curState.addTransition(transition);
                curState = nextState;
            }

            curState.addTransition(endTransitionData.createTransition(endState, null));

            //add end transitions
            //foreach(var end in endTransitions)
            //{
            //    var prevAreaState = areaStates[end.Key - 2];
            //    prevAreaState.addTransition(end.Value.createTransition(endState));
            //}

            var model = new CHnMModel(startState, endState);

            return(model);
        }
コード例 #5
0
 public abstract CHnMModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap);
コード例 #6
0
        public static void DrawStrokeMap(GestureRecognitionLib.CHnMM.StrokeMap strokeMap, Canvas DrawCanvas, Color color, bool isTranslationInvariant)
        {
            var h = DrawCanvas.ActualHeight;
            var w = DrawCanvas.ActualWidth;

            var offsetX = 0d;
            var offsetY = 0d;

            if (isTranslationInvariant)
            {
                //move translationinvariant gestures to canvas center
                var minX = strokeMap.Areas.Cast <Circle>().Min(a => a.X);
                var maxX = strokeMap.Areas.Cast <Circle>().Max(a => a.X);

                var minY = strokeMap.Areas.Cast <Circle>().Min(a => a.Y);
                var maxY = strokeMap.Areas.Cast <Circle>().Max(a => a.Y);

                double width  = maxX - minX;
                double height = maxY - minY;

                double traceCenterX = minX + (width / 2);
                double traceCenterY = minY + (height / 2);

                offsetX = 0.5 - traceCenterX;
                offsetY = 0.5 - traceCenterY;
            }

            //int i = 1;
            foreach (var iarea in strokeMap.Areas)
            {
                var area = iarea as Circle;

                var absX          = (area.X + offsetX) * w;
                var absY          = (area.Y + offsetY) * h;
                var absCircleW    = area.Radius * w * 2;
                var absCircleH    = area.Radius * h * 2;
                var absTolCircleW = area.ToleranceRadius * w * 2;
                var absTolCircleH = area.ToleranceRadius * h * 2;

                var circle = new Ellipse();
                circle.Width           = absCircleW;
                circle.Height          = absCircleH;
                circle.Fill            = null;
                circle.Stroke          = new SolidColorBrush(color);
                circle.StrokeThickness = 1.5;
                circle.SetValue(Canvas.LeftProperty, absX - absCircleW / 2);
                circle.SetValue(Canvas.TopProperty, absY - absCircleH / 2);

                var tolCircle = new Ellipse();
                tolCircle.Width           = absTolCircleW;
                tolCircle.Height          = absTolCircleH;
                tolCircle.Fill            = null;
                tolCircle.Stroke          = new SolidColorBrush(Color.Multiply(color, 0.9f));
                tolCircle.StrokeDashArray = new DoubleCollection(new double[] { 3 });
                //tolCircle.StrokeDashOffset = 2;
                tolCircle.StrokeThickness = 1;
                tolCircle.SetValue(Canvas.LeftProperty, absX - absTolCircleW / 2);
                tolCircle.SetValue(Canvas.TopProperty, absY - absTolCircleH / 2);

                //var curFillBrush = baseFillBrush.Clone();
                //curFillBrush.Opacity = opacity;

                //circle.Fill = curFillBrush;
                ////circle.SetValue(Ellipse.FillProperty, FillBrush);
                //circle.Stroke = StrokeBrush;
                //circle.SetValue(Canvas.LeftProperty, (double)(p.X * 600 - size));
                //circle.SetValue(Canvas.TopProperty, (double)(p.Y * 600 - size));

                DrawCanvas.Children.Add(circle);
                DrawCanvas.Children.Add(tolCircle);
            }
        }