コード例 #1
0
ファイル: InkFile.cs プロジェクト: nguonly/KHWR.kNN
    public TraceGroup ReadFromInkFile(string path)
    {
      var outTraceGroup = new TraceGroup();
      var input = new FileStream(path, FileMode.Open, FileAccess.Read);
      var fileReader = new StreamReader(input);
      var strLine = "";
      char[] splitter = { ' ' };

      var captureDevice = new CaptureDevice { SamplingRate = 100, Latency = 0f };
      while(!fileReader.EndOfStream)
      {
        strLine = fileReader.ReadLine();
        if (strLine == null) continue;
        
        //Read header info
        if (strLine.Contains(".X_POINTS_PER_INCH"))
        {
          var strToken = strLine.Split(splitter, StringSplitOptions.None);
          captureDevice.XDpi = Convert.ToInt32(strToken[1]);
        }

        if (strLine.Contains(".Y_POINTS_PER_INCH"))
        {
          var strToken = strLine.Split(splitter, StringSplitOptions.None);
          captureDevice.YDpi = Convert.ToInt32(strToken[1]);
        }

        if (strLine.Contains(".POINTS_PER_SECOND"))
        {
          var strToken = strLine.Split(splitter, StringSplitOptions.None);
          //use later
        }

        if (!strLine.Trim().Equals(".PEN_DOWN")) continue;
        
        var strCoord = "";

        var trace = new Trace();
        while(!(strCoord = fileReader.ReadLine()?? "").Trim().Equals(".PEN_UP") && !fileReader.EndOfStream)
        {
          
          var strToken = strCoord.Split(splitter, StringSplitOptions.None);

          var x = Convert.ToInt32(strToken[0]);
          var y = Convert.ToInt32(strToken[1]);

          trace.Points.Add(new PenPoint{X=x, Y=y});
        }
        outTraceGroup.Traces.Add(trace);
      }

      fileReader.Close();
      input.Close();

      outTraceGroup.CaptureDevice = captureDevice;

      return outTraceGroup;
    }
コード例 #2
0
ファイル: PreProcessing.cs プロジェクト: nguonly/KHWR.kNN
    public PreProcessing()
    {
      _captureDevice = new CaptureDevice();
      _captureDevice.XDpi = 2000;
      _captureDevice.YDpi = 2000;
      _captureDevice.Latency = 0.0f;
      _captureDevice.SamplingRate = 100;

      _preserveAspectRatio = true;
    }
コード例 #3
0
ファイル: RecognizerForm.cs プロジェクト: nguonly/KHWR.kNN
    private void btnRecognizer_Click(object sender, EventArgs e)
    {
      var traceGroup = _drawingInk.Ink.ToTraceGroup();
      var captureDevice = new CaptureDevice { XDpi = 300, YDpi = 300, SamplingRate = 100, Latency = 0f };
      traceGroup.CaptureDevice = captureDevice;
      var results = _recognizer.Recognize(traceGroup);

      var buffer = new StringBuilder();
      foreach (var r in results)
      {
        buffer.AppendLine(r.ToString());
      }
      lblResult.Text = buffer.ToString();

      lblGuessChar.Text = results[0].ShapeCharacter;
    }
コード例 #4
0
ファイル: InkFile.cs プロジェクト: nguonly/KHWR.kNN
        public TraceGroup ReadFromInkFile(string path)
        {
            var outTraceGroup = new TraceGroup();
            var input         = new FileStream(path, FileMode.Open, FileAccess.Read);
            var fileReader    = new StreamReader(input);
            var strLine       = "";

            char[] splitter = { ' ' };

            var captureDevice = new CaptureDevice {
                SamplingRate = 100, Latency = 0f
            };

            while (!fileReader.EndOfStream)
            {
                strLine = fileReader.ReadLine();
                if (strLine == null)
                {
                    continue;
                }

                //Read header info
                if (strLine.Contains(".X_POINTS_PER_INCH"))
                {
                    var strToken = strLine.Split(splitter, StringSplitOptions.None);
                    captureDevice.XDpi = Convert.ToInt32(strToken[1]);
                }

                if (strLine.Contains(".Y_POINTS_PER_INCH"))
                {
                    var strToken = strLine.Split(splitter, StringSplitOptions.None);
                    captureDevice.YDpi = Convert.ToInt32(strToken[1]);
                }

                if (strLine.Contains(".POINTS_PER_SECOND"))
                {
                    var strToken = strLine.Split(splitter, StringSplitOptions.None);
                    //use later
                }

                if (!strLine.Trim().Equals(".PEN_DOWN"))
                {
                    continue;
                }

                var strCoord = "";

                var trace = new Trace();
                while (!(strCoord = fileReader.ReadLine() ?? "").Trim().Equals(".PEN_UP") && !fileReader.EndOfStream)
                {
                    var strToken = strCoord.Split(splitter, StringSplitOptions.None);

                    var x = Convert.ToInt32(strToken[0]);
                    var y = Convert.ToInt32(strToken[1]);

                    trace.Points.Add(new PenPoint {
                        X = x, Y = y
                    });
                }
                outTraceGroup.Traces.Add(trace);
            }

            fileReader.Close();
            input.Close();

            outTraceGroup.CaptureDevice = captureDevice;

            return(outTraceGroup);
        }