void _inkCanvas_StrokeCollected_StrokeToImage(object sender, InkCanvasStrokeCollectedEventArgs e) { InkCanvas inkCanvas = (InkCanvas)sender; if (analyze.RootNode.Strokes.IndexOf(inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]) == -1) { analyze.AddStroke(inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]); } analyze.BackgroundAnalyze(); string analyzeStr = analyze.GetRecognizedString(); //Stream streamOpen = new FileStream("pack://siteoforigin:,,,/xml/StrokeToImage.xml", FileMode.Open);//提示“不支持指定格式” Stream streamOpen = new FileStream(GlobalValues.FilesPath + "/WPFInk/WPFInk/bin/Debug/xml/StrokeToImage.xml", FileMode.Open); using (System.IO.StreamReader streamReader = new System.IO.StreamReader(streamOpen)) { XmlReaderSettings settings = new XmlReaderSettings(); XmlReader Reader = XmlReader.Create(streamReader, settings); while (Reader.Read()) { if (Reader.NodeType == XmlNodeType.Element) { if (Reader.Name == "Image") { Reader.MoveToAttribute("stroke"); string strokeStr = Reader.Value; Reader.MoveToAttribute("imageName"); searchStrokes(strokeStr, Reader.Value, inkCanvas); } } } } }
private void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { InkAnalyzer analyser = new InkAnalyzer(); analyser.AddStrokes(_inkCanvas.Strokes); analyser.Analyze(); _inkResults.Text = analyser.GetRecognizedString(); e.Handled = false; }
// IACore,IAWinFx // C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 // IALoader // C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる // http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310 private string InkAnalyze(InkCanvas canvas) { InkAnalyzer theInkAnalyzer = new InkAnalyzer(); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット theInkAnalyzer.AddStrokes(canvas.Strokes); theInkAnalyzer.SetStrokesType(canvas.Strokes, StrokeType.Writing); // 文字を解析 theInkAnalyzer.Analyze(); // 文字を解析した結果の第1候補を返す return(theInkAnalyzer.GetRecognizedString()); }
static public bool IsChar(this Stroq stroke, string charset) { System.Windows.Ink.InkAnalyzer ia = new InkAnalyzer(); ia.AddStroke(stroke.BackingStroke); //AnalysisHintNode node = ia.CreateAnalysisHint(); //node.Factoid = "IS_ONECHAR"; //node.CoerceToFactoid = true; //node.Location.MakeInfinite(); AnalysisStatus astat = ia.Analyze(); string reco = ia.GetRecognizedString(); Console.WriteLine("Recognized:<" + reco + ">"); if (astat.Successful && reco != "Other") { return(charset.Contains(reco[0])); } return(false); }
public HttpResponseMessage<String> Recognize(string strokes) { var strokePointsData = JsonConvert.DeserializeObject<dynamic>(strokes); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return new HttpResponseMessage<string>(recognizedString); } else return new HttpResponseMessage<string>("Data not recognized"); }
public String Recognize([FromBody] Results.Stroke stroke) { var strokePointsData = JsonConvert.DeserializeObject<dynamic>(stroke.Json); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return recognizedString; } else return "Data not recognized"; }
private void btnAnalyze_Click(object sender, RoutedEventArgs e) { InkAnalyzer theInkAnalyzer = new InkAnalyzer(); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット theInkAnalyzer.AddStrokes(InkCanvas1.Strokes); theInkAnalyzer.SetStrokesType(InkCanvas1.Strokes, StrokeType.Writing); // 文字を解析 theInkAnalyzer.Analyze(); // 文字を解析した結果の第1候補を表示する MessageBox.Show(theInkAnalyzer.GetRecognizedString()); // その他の候補を表示する AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates(); foreach (var alternate in alternates) { MessageBox.Show(alternate.RecognizedString); } }
public HttpResponseMessage <String> Recognize(string strokes) { var strokePointsData = JsonConvert.DeserializeObject <dynamic>(strokes); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return(new HttpResponseMessage <string>(recognizedString)); } else { return(new HttpResponseMessage <string>("Data not recognized")); } }
public String Recognize([FromBody] Results.Stroke stroke) { var strokePointsData = JsonConvert.DeserializeObject <dynamic>(stroke.Json); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return(recognizedString); } else { return("Data not recognized"); } }
public override void _presenter_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { InkCanvas inkCanvas = (InkCanvas)sender; Stroke lastStroke = inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]; if (analyze.RootNode.Strokes.IndexOf(lastStroke) == -1) { analyze.AddStroke(inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]); } analyze.BackgroundAnalyze(); string analyzeStr = analyze.GetRecognizedString(); MyGraphic MyGraphicContrainStroke = _inkCollector.Sketch.getMyGraphicContrainStroke(lastStroke); if (MyGraphicContrainStroke != null) { if (MyGraphicContrainStroke.textStrokeCollection.IndexOf(lastStroke) == -1) { MyGraphicContrainStroke.addTextStroke(lastStroke); MyGraphicContrainStroke.Text = analyzeStr; //Console.WriteLine("analyzeStr:" + analyzeStr); } } }
public MyInkAnalyzer(StrokeCollection strokeCollection) { if (strokeCollection.Count > 0) { _strokeCollection = strokeCollection; analyze = new InkAnalyzer(); //2052:简体中文 1033:英语 analyze.AddStrokes(strokeCollection, GlobalValues.InkAnalyzerLanguageId); //analyze.BackgroundAnalyze(); AnalysisStatus status = analyze.Analyze(); if (status.Successful) { analyzeResults = analyze.GetRecognizedString(); } else { analyzeResults = "Recognition Failed"; } analyze.RemoveStrokes(_strokeCollection); } }
///Draw handwritings //private void DrawHandwriting(Skeleton skeleton, DrawingContext drawingContext) //{ // Joint handRightJoint = skeleton.Joints[JointType.HandRight]; // Point handRightPoint = SkeletonPointToScreen(handRightJoint.Position); // Joint handLeftJoint = skeleton.Joints[JointType.HandLeft]; // Point handLeftPoint = SkeletonPointToScreen(handLeftJoint.Position); // if (handLeftPoint.Y < handRightPoint.Y) // { // if (!handwritings.Points.Contains(handRightPoint)) // { // handwritings.Points.Add(handRightPoint); // } // for (int i = 0; i < handwritings.Points.Count - 1; i++) // { // drawingContext.DrawLine(new Pen(Brushes.Yellow, 3), handwritings.Points[i], handwritings.Points[i + 1]); // } // } // else // handwritings.Points.Clear(); // To clear the old painting // if (handwritings.Points.Count > 0) // { // StylusPointCollection spc = new StylusPointCollection(); // for (int i = 0; i < handwritings.Points.Count; i++) // { // spc.Add(new StylusPoint(handwritings.Points[i].X, handwritings.Points[i].Y)); // } // Stroke s = new Stroke(spc); // StrokeCollection sc = new StrokeCollection(new Stroke[] { s }); // InkAnalyzer inkAnalyzer = new InkAnalyzer(); // inkAnalyzer.AddStrokes(sc); // AnalysisStatus status = inkAnalyzer.Analyze(); // if (status.Successful) // { // textBlockResult.Text = inkAnalyzer.GetRecognizedString(); // sc.Clear(); // } // } //} private void DrawColorfulHandwriting(Skeleton skeleton, DrawingContext drawingContext) { Joint handRightJoint = skeleton.Joints[JointType.HandRight]; Point handRightPoint = SkeletonPointToScreen(handRightJoint.Position); Joint handLeftJoint = skeleton.Joints[JointType.HandLeft]; Point handLeftPoint = SkeletonPointToScreen(handLeftJoint.Position); int depth = SkeletonDepthToScreen(handRightJoint.Position); //SolidColorBrush brush = new SolidColorBrush(); int fontsize; if (depth < 1500) { //brush = Brushes.White; fontsize = 36; } else if (depth < 2000) { //brush = Brushes.Pink; fontsize = 56; } else { //brush = Brushes.Red; fontsize = 72; } if (handLeftPoint.Y < handRightPoint.Y) { if (!handwritings.Points.Contains(handRightPoint)) { handwritings.Points.Add(handRightPoint); } for (int i = 0; i < handwritings.Points.Count - 1; i++) { drawingContext.DrawLine(new Pen(brush, 3), handwritings.Points[i], handwritings.Points[i + 1]); } //StartSineWave(depth); } else { StopSineWave(); handwritings.Points.Clear(); // To clear the old painting } if (handwritings.Points.Count > 0) { StylusPointCollection spc = new StylusPointCollection(); for (int i = 0; i < handwritings.Points.Count; i++) { spc.Add(new StylusPoint(handwritings.Points[i].X, handwritings.Points[i].Y)); } Stroke s = new Stroke(spc); StrokeCollection sc = new StrokeCollection(new Stroke[] { s }); InkAnalyzer inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(sc); AnalysisStatus status = inkAnalyzer.Analyze(); if (status.Successful) { textBlockResult.Text = inkAnalyzer.GetRecognizedString(); textBlockResult.FontSize = fontsize; sc.Clear(); } } }
private void OCRText(int mode = 0) { StrokeCollection sc; switch (mode) { case 0: sc = OCRCanvas.Strokes; break; case 1: sc = TegakiCanvas.GetSelectedStrokes(); break; default: return; } ia = new InkAnalyzer(); if (sc.Count == 0) { return; } CustomRecognizerNode node; double x, y; int height; getStrokeZahyo(sc, out x, out y, out height); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット if (EngineList.SelectedItem != null) { node = ia.CreateCustomRecognizer((Guid)EngineList.SelectedValue); ia.AddStrokesToCustomRecognizer(sc, node); } else { ia.AddStrokes(sc); } ia.SetStrokesType(sc, StrokeType.Writing); // 文字を解析 ia.Analyze(); //罫線にピタッとなるようにする y = ((int)((y + lineMargine / 2) / lineMargine) * lineMargine) + 1 * (int)((y + lineMargine / 2) / lineMargine); height = (int)((height + lineMargine / 2) / lineMargine) * lineMargine; if (height >= 8) { TextBlock tb = new TextBlock() { Text = ia.GetRecognizedString(), FontSize = height - 8, VerticalAlignment = System.Windows.VerticalAlignment.Top, LineStackingStrategy = LineStackingStrategy.BlockLineHeight, LineHeight = height }; //noteRoot.Children.Add(tb); TegakiCanvas.Children.Add(tb); InkCanvas.SetLeft(tb, x); InkCanvas.SetTop(tb, y); } //textBox1.Text += ia.GetRecognizedString(); switch (mode) { case 0: OCRCanvas.Strokes.Clear(); break; case 1: foreach (Stroke s in sc) { TegakiCanvas.Strokes.Remove(s); } break; } /* * // その他の候補を表示する * AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates(); * foreach (var alternate in alternates) * MessageBox.Show(alternate.RecognizedString); */ }
// IACore,IAWinFx // C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 // IALoader // C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる // http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310 private string InkAnalyze( InkCanvas canvas ) { InkAnalyzer theInkAnalyzer = new InkAnalyzer(); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット theInkAnalyzer.AddStrokes( canvas.Strokes ); theInkAnalyzer.SetStrokesType( canvas.Strokes, StrokeType.Writing ); // 文字を解析 theInkAnalyzer.Analyze(); // 文字を解析した結果の第1候補を返す return theInkAnalyzer.GetRecognizedString(); }