Exemple #1
0
        /// <summary>
        /// Recognizes the strokes of the sketch using the Ink.
        /// </summary>
        /// <param name="args">An unlabeled Sketch and a UserTriggered flag</param>
        /// <returns>A Labeled Sketch and </returns>
        public override RecognitionResult Recognize(RecognitionArgs args)
        {
            RecognitionResult result = new RecognitionResult();

            result.UserTriggered = args.UserTriggered;

            // Only recognize when necessary
            if (!args.UserTriggered)
            {
                return(result);
            }

            // Run recognition and fill result
            Sketcher sketcher = new Sketcher();

            iTool = sketcher.InkPanel.InkTool;
            iTool.Clusterer.ImageRecognizer.RecognitionCompleted += new RecognitionCompletedEventHandler(ImageRecognizer_RecognitionCompleted);
            settingsFilename = sketcher.SettingsFilename;
            dir = sketcher.BaseDirectory;

            try
            {
                iTool.Clusterer.ImageRecognizer.m_RecognitionComplete = false;
                // Try to use InkTool
                bool success = iTool.ClassifySketch(args.Sketch, settingsFilename, dir);
                StrokeClassifier.StrokeClassifierResult clResult = iTool.Clusterer.Classifier.Classify();
                StrokeGrouper.StrokeGrouperResult       grResult = iTool.Clusterer.Grouper.Group(clResult.AllClassifications);
                List <Cluster> initialClusters = new List <Cluster>();//iTool.Clusterer.CreateClusters(grResult);
                ImageRecognizerWrapper.ImageRecognizerResults imgResult = iTool.Clusterer.GetImageResults(initialClusters);
                //while (!iTool.Clusterer.InitialClustersDone);
                //iTool.Clusterer.ImageRecognizer.RecognizeST(iTool.Clusterer.
                rSketch       = iTool.MakeSketch(imgResult.ScoredClusters);
                result.Sketch = rSketch;
            }
            catch (Exception e)
            {
                // Catch all other exceptions
                System.Windows.MessageBox.Show("General Exception from sketch recognizer component: \n" + e.Message);

                // Return unrecognized sketch
                result.Sketch = args.Sketch;
            }

            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Throws OnSelect. Will begin drawing a line by activating the draw() subroutine in the current
 /// sketcher, then will overwrite the reference to that sketcher with a newly instantiated on when done
 /// </summary>
 private void OnTap()
 {
     if (FocusedObject != null && FocusedObject.CompareTag("picker"))
     {
         FocusedObject.SendMessage("OnSelect", SendMessageOptions.DontRequireReceiver);
     }
     else
     {
         if (isDrawing)
         {
             mSketcher.stopDrawing();
             pastSketches.Add(mSketcher);
             mSketcher = ((GameObject)Instantiate(mSketchPrefab)).GetComponent <Sketcher>();
             mSketcher.GetComponent <LineRenderer>().SetColors(mWarehouse.currentColor, mWarehouse.currentColor);
             mSketcher.cursor     = cursor;
             mWarehouse.mSketcher = mSketcher;
         }
         else
         {
             mSketcher.startDrawing();
         }
         isDrawing = !isDrawing;
     }
 }