/// <summary> /// /// </summary> /// <param name="strokes"></param> internal String recognize(Strokes strokes, out RecognitionAlternates alternates) { RecognizerContext rc = new RecognizerContext(); rc.Strokes = strokes; try { RecognitionStatus status; RecognitionResult result; result = rc.Recognize(out status); if (status == RecognitionStatus.NoError) { RecognitionAlternates alternatives = result.GetAlternatesFromSelection(); alternates = alternatives; return(result.TopString); } else { Console.WriteLine("Error in recognition."); } } catch { Console.WriteLine("Exception in recognition."); } alternates = null; return(null); }
// Recognizes handwriting by using RecognizerContext private void buttonClick(object sender, RoutedEventArgs e) { using (MemoryStream ms = new MemoryStream()) { //theInkCanvas.Strokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { //textBox1.Text = result.TopString; //else MessageBox.Show("Recognition failed"); } } else { MessageBox.Show("No stroke detected"); } } } }
private RecognizerContext recognizectx; // REM 识别器上下文 // Private myInkCollector As InkCollector // REM 初始化墨迹识别器 public void InitRecognizer() { myRecognizers = new Recognizers(); strokes = ink.CreateStrokes(); recognizectx = myRecognizers.GetDefaultRecognizer().CreateRecognizerContext(); recognizectx.Strokes = strokes; }
private void ink_() { Recognizers recos = new Recognizers(); Recognizer chineseReco = recos.GetDefaultRecognizer(); rct = chineseReco.CreateRecognizerContext(); }
/// <summary> /// 文字認識処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonClick(object sender, RoutedEventArgs e) { using (var ms = new MemoryStream()) { theInkCanvas.Strokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (var context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { textBox1.Text = result.TopString; } else { MessageBox.Show("認識に失敗しました"); } } else { MessageBox.Show("文字が検出されませんでした"); } } } }
private void RecognizeButton_Clicked(object sender, RoutedEventArgs e) { Candidates.Clear(); if (inkCanvas.Strokes.Count <= 0) { return; } using (var stream = new MemoryStream()) { inkCanvas.Strokes.Save(stream); var ink = new Ink(); ink.Load(stream.ToArray()); using (var context = new RecognizerContext()) { context.Strokes = ink.Strokes; var result = context.Recognize(out RecognitionStatus status); if (status == RecognitionStatus.NoError) { var candidates = result.GetAlternatesFromSelection(); foreach (var candidate in candidates) { Candidates.Add(candidate.ToString()); } } } } }
public string Recognize() { using (MemoryStream ms = new MemoryStream()) { // Build an inkCollector containing the strokes canvas.Strokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = recognizer.CreateRecognizerContext()) { RecognitionStatus status; context.Factoid = Factoid.WordList; // Magic smoke for name recognition context.Strokes = ink.Strokes; // Cannot do if there are no strokes if (ink.Strokes.Count > 0) { var results = context.Recognize(out status); if (status == RecognitionStatus.NoError) { return(results.ToString()); } } } } return(""); }
private void Recognise() { if (inkCanvas.Strokes.Count == 0) { tbRecognised.Text = string.Empty; return; } using (MemoryStream ms = new MemoryStream()) { inkCanvas.Strokes.Save(ms); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = jpnRecognizer.CreateRecognizerContext()) { context.Strokes = ink.Strokes; var result = context.Recognize(out var status); if (status == RecognitionStatus.NoError) { tbRecognised.Text = result.TopString; } else { MessageBox.Show("Recognition failed"); } } } }
public string ToText(StrokeCollection strokes) { using (var ms = new MemoryStream()) { if (strokes == null) { return(null); } strokes.Save(ms); var ink = new Ink(); ink.Load(ms.ToArray()); if (ink.Strokes.Count <= 0) { return(null); } using (var context = new RecognizerContext()) { context.Strokes = ink.Strokes; var result = context.Recognize(out RecognitionStatus status); return(status == RecognitionStatus.NoError ? result.TopString : null); } } }
/// <summary> /// Recognize ink data using the default recognizer. /// </summary> /// <returns>The string containing the top recognition result.</returns> protected String RecognizeInkData() { Debug.Assert(InkEnabled, null, "Client must be ink-enabled"); // Obtain the ink associated with this control Ink ink = inkOverlay.Ink; if (ink.Strokes.Count > 0) { // Attempt to create a recognition context and use it to // retrieve the top alternate. try { RecognizerContext recognizerContext = new RecognizerContext(); RecognitionStatus recognitionStatus; recognizerContext.Strokes = ink.Strokes; RecognitionResult recognitionResult = recognizerContext.Recognize(out recognitionStatus); if ((recognitionStatus == RecognitionStatus.NoError) && (null != recognitionResult)) { return(recognitionResult.TopString); } } catch (Exception) { // An exception will occur if the client does not have // any handwriting recognizers installed on their system. // In this case, we default to returning an empty string. } } return(String.Empty); }
private void HandwritingPad_Load(object sender, EventArgs e) { ic = new InkCollector(PicInkPad.Handle); ic.Enabled = true; Recognizers recos = new Recognizers(); Recognizer chineseReco = recos.GetDefaultRecognizer(); rct = chineseReco.CreateRecognizerContext(); rct.Strokes = ic.Ink.Strokes; }
private void ink_Here() { Recognizers recos = new Recognizers(); Recognizer chineseReco = recos.GetDefaultRecognizer(); rct = chineseReco.CreateRecognizerContext(); rct.RecognitionFlags = Microsoft.Ink.RecognitionModes.WordMode; this.rct.RecognitionWithAlternates += new RecognizerContextRecognitionWithAlternatesEventHandler(rct_RecognitionWithAlternates); }
private void ButtonClick(object sender, RoutedEventArgs e) { using (var ms = new MemoryStream()) { TheInkCanvas.Strokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (var context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; var result = context.Recognize(out var status); string temp = null; foreach (var test in result.GetAlternatesFromSelection()) { if (!int.TryParse(test.ToString(), out _)) { continue; } temp = test.ToString(); break; } if (status == RecognitionStatus.NoError) { //TextBox1.Text = result.TopString; if (temp == null) { if (result.TopString.ToString() == "+" || result.TopString == "-") { temp = result.TopString; } else { temp = "NaN"; } } TextBox1.Text = temp; } else { MessageBox.Show("Recognition failed"); } } else { MessageBox.Show("No stroke detected"); } } } }
private void Form1_Load(object sender, EventArgs e) { myInkCollector = new InkCollector(pictureBox1.Handle); myInkCollector.Enabled = true; recoContext = new RecognizerContext(); strokesToRecognize = myInkCollector.Ink.CreateStrokes(); recoContext.Strokes = strokesToRecognize; recoContext.RecognitionWithAlternates += new RecognizerContextRecognitionWithAlternatesEventHandler(reco_RWA); myInkCollector.Stroke += InkOverlay_Stroke; }
public TextRecognizer() { _microsoftTextRecognizer = new RecognizerContext(); // Specify what words should be recognizable, to enhance accuracy _microsoftTextRecognizer.WordList = createWordList(); // Indicate that we want to only use words from this wordlist. _microsoftTextRecognizer.Factoid = Factoid.WordList; _microsoftTextRecognizer.RecognitionFlags = RecognitionModes.WordMode | RecognitionModes.Coerce; }
private void CreateRecognizer(InkOverlay overlay) { Recognizers recognizers = new Recognizers(); Recognizer english = recognizers.GetDefaultRecognizer(); context = english.CreateRecognizerContext(); WordList wordList = new WordList(); for (int i = 0; i < 100; ++i) wordList.Add(i.ToString()); context.WordList = wordList; context.Factoid = Factoid.WordList; context.RecognitionFlags = RecognitionModes.Coerce; }
/// <summary> /// Sets the recognizer engine used to convert strokes to text. /// </summary> /// <param name="engineId">The GUID of the recognizer engine.</param> /// <exception cref="ArgumentException"> /// Thrown if the engine is invalid or does not exist. /// </exception> public void SetEngine(Guid engineId) { EnsureNotDisposed(); _recognizerContext?.Dispose(); Recognizer engineImpl = _recognizers .Cast <Recognizer>() .FirstOrDefault(x => x.Id == engineId); if (engineImpl == null) { throw new ArgumentException("Engine not found: " + engineId); } _recognizerContext = engineImpl.CreateRecognizerContext(); }
public Canvas() { InitializeComponent(); graph = new Graph(); animations = new ArrayList(); animStarted = false; weight = -1; prevEdgeHit = null; // Declare repaint optimizations. base.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); this.Paint += new PaintEventHandler(Canvas_Paint); inkOverlay = new InkOverlay(this.Handle, true); //attach to form, allow use of mouse for input inkOverlay.CollectionMode = CollectionMode.InkOnly; // allow ink only, no gestures inkOverlay.AutoRedraw = false; // Dynamic rendering only; we do all the painting. DrawingAttributes da = new DrawingAttributes(); da.AntiAliased = true; //Makes everything nice and smooth lookin' da.Transparency = 0; da.PenTip = Microsoft.Ink.PenTip.Ball; da.Width = 70.0f; inkOverlay.DefaultDrawingAttributes = da; //Triggered at each pen stroke inkOverlay.Stroke += new InkCollectorStrokeEventHandler(inkOverlay_Stroke); //Triggered at each eraser stroke inkOverlay.StrokesDeleting += new InkOverlayStrokesDeletingEventHandler(inkOverlay_StrokesDeleting); //Triggered when a selection of strokes is moved inkOverlay.SelectionMoved += new InkOverlaySelectionMovedEventHandler(inkOverlay_SelectionMoved); //Triggered when a selection of strokes is resized inkOverlay.SelectionResized += new InkOverlaySelectionResizedEventHandler(inkOverlay_SelectionResized); inkOverlay.Enabled = true; myRecognizer = new RecognizerContext(); myRecognizer.Strokes = inkOverlay.Ink.CreateStrokes(); edgeTimer = new System.Timers.Timer(TIME_INTERVAL); edgeTimer.AutoReset = true; edgeTimer.Elapsed += new ElapsedEventHandler(edgeTimer_Elapsed); edgeTimer.Enabled = true; }
// Se produce el reconocimento al dispararse el timer private void Timer_Tick(object sender, EventArgs e) { using (MemoryStream ms = new MemoryStream()) { inkCanvas.Strokes.Save(ms); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { if (result == null) { ResetCanvasAndTimer(); return; } var resultString = result.TopString; if (!isAcceptedChar(resultString)) { ResetCanvasAndTimer(); return; } bool isNumeric = int.TryParse(resultString, out int number); if (!isNumeric) { number = 0; } _solicitudCambioNúmero(number); ResetCanvasAndTimer(); } } } } }
private void Timer_Tick(object sender, EventArgs e) { using (MemoryStream ms = new MemoryStream()) { calculatorCanvas.Strokes.Save(ms); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { // Se borra la expresión del text box si se va a evaluar una nueva expresión if (expressionDone) { resultBox.Text = ""; expressionDone = false; } context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { if (RB_Mode1.IsChecked == true) { HandleMode1(result); } else { HandleMode2(result); } } else { MessageBox.Show("Recognition failed"); } } } } }
/// <summary> /// Event Handle recognize button click event /// </summary> /// <param name="sender">The control that raised the event.</param> /// <param name="e">The event arguments.</param> private void btnRecognize_Click(object sender, System.EventArgs e) { // Check to ensure that the user has at least one recognizer installed // Note that this is a preventive check - otherwise, an exception will // occur during recognition. if (0 == myRecognizers.Count) { MessageBox.Show("There are no handwriting recognizers installed. You need to have at least one in order to recognize ink."); } else { // Note that the Strokes' ToString() method is a // shortcut for retrieving the best match using the // default recognizer. The same result can also be // obtained using the RecognizerContext. For an // example, uncomment the following lines of code: // RecognizerContext myRecoContext = new RecognizerContext(); myRecoContext.Factoid = "(0|1|X)"; RecognitionStatus status; RecognitionResult recoResult; // myRecoContext.Strokes = myInkCollector.Ink.Strokes; recoResult = myRecoContext.Recognize(out status); txtResults.SelectedText = recoResult.TopString; //txtResults.SelectedText = myInkCollector.Ink.Strokes.ToString(); // If the mouse is pressed, do not perform the deletion - // this prevents deleting a stroke that is still being drawn if (!myInkCollector.CollectingInk) { // Once the strokes have been recognized, delete them myInkCollector.Ink.DeleteStrokes(); // Repaint the drawing area gbInkArea.Refresh(); } } }
/// <summary> /// 笔记识别 /// </summary> /// <param name="strokes"></param> /// <returns></returns> public List <string> Recognize(StrokeCollection strokes) { List <string> lstr = new List <string>(); using (MemoryStream ms = new MemoryStream()) { strokes.Save(ms); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { //lstr.Add(result.TopString);//最可能的识别 //获取所有备选词 RecognitionAlternates alternates = result.GetAlternatesFromSelection(0, result.TopString.Length, 10); foreach (RecognitionAlternate alternate in alternates) { lstr.Add(alternate.ToString()); } } //else // lstr.Add("识别失败"); } //else // lstr.Add("没有侦测到签名"); } return(lstr); } }
private void button3_Click(object sender, EventArgs e) { Candidates.Clear(); if (InkOverlay.Ink.Strokes.Count <= 0) { return; } using (var context = new RecognizerContext()) { context.Strokes = InkOverlay.Ink.Strokes; var result = context.Recognize(out RecognitionStatus status); if (status == RecognitionStatus.NoError) { var candidates = result.GetAlternatesFromSelection(); foreach (var candidate in candidates) { Candidates.Add(candidate.ToString()); } } } comboBox1.DataSource = null; comboBox1.DataSource = Candidates; comboBox1.SelectedIndex = 0; }
/// <summary> /// obtains and returns alternative recognition results /// </summary> /// <param name="strokes">the strokes to be recognized</param> /// <returns>list of alternative</returns> private RecognitionAlternates getAlternative(Strokes strokes) { try { RecognizerContext context = new RecognizerContext(); context.Strokes = strokes; RecognitionStatus status; RecognitionResult result = context.Recognize(out status); RecognitionAlternates ra; if (RecognitionStatus.NoError == status) { ra = result.GetAlternatesFromSelection(); } else { ra = null; } return(ra); } catch (Exception) { return(null); } }
private void InkCanvas_SelectionChanged(object sender, EventArgs e) { var selectedStrokes = InkCanvas.GetSelectedStrokes(); using (MemoryStream ms = new MemoryStream()) { selectedStrokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext myRecoContext = new RecognizerContext()) { RecognitionStatus status = RecognitionStatus.ProcessFailed; myRecoContext.Strokes = ink.Strokes; try { var recoResult = myRecoContext.Recognize(out status); if (status == RecognitionStatus.NoError) { textBlock.Text = recoResult.TopString; //InkCanvas.Strokes.Clear(); } else { MessageBox.Show("ERROR: " + status.ToString()); } } catch (Exception) { //MessageBox.Show("ERROR: " + status.ToString()); } } } }
/// <summary> /// /// </summary> /// <param name="strokes"></param> internal String recognize(Strokes strokes, out RecognitionAlternates alternates) { RecognizerContext rc = new RecognizerContext(); rc.Strokes = strokes; try { RecognitionStatus status; RecognitionResult result; result = rc.Recognize(out status); if (status == RecognitionStatus.NoError) { RecognitionAlternates alternatives = result.GetAlternatesFromSelection(); alternates = alternatives; return result.TopString; } else { Console.WriteLine("Error in recognition."); } } catch { Console.WriteLine("Exception in recognition."); } alternates = null; return null; }
public Canvas() { InitializeComponent(); graph = new Graph(); animations = new ArrayList(); animStarted = false; weight = -1; prevEdgeHit = null; // Declare repaint optimizations. base.SetStyle( ControlStyles.UserPaint| ControlStyles.AllPaintingInWmPaint| ControlStyles.DoubleBuffer, true); this.Paint += new PaintEventHandler(Canvas_Paint); inkOverlay = new InkOverlay(this.Handle, true); //attach to form, allow use of mouse for input inkOverlay.CollectionMode = CollectionMode.InkOnly; // allow ink only, no gestures inkOverlay.AutoRedraw = false; // Dynamic rendering only; we do all the painting. DrawingAttributes da = new DrawingAttributes(); da.AntiAliased = true; //Makes everything nice and smooth lookin' da.Transparency = 0; da.PenTip = Microsoft.Ink.PenTip.Ball; da.Width = 70.0f; inkOverlay.DefaultDrawingAttributes = da; //Triggered at each pen stroke inkOverlay.Stroke += new InkCollectorStrokeEventHandler(inkOverlay_Stroke); //Triggered at each eraser stroke inkOverlay.StrokesDeleting += new InkOverlayStrokesDeletingEventHandler(inkOverlay_StrokesDeleting); //Triggered when a selection of strokes is moved inkOverlay.SelectionMoved += new InkOverlaySelectionMovedEventHandler(inkOverlay_SelectionMoved); //Triggered when a selection of strokes is resized inkOverlay.SelectionResized +=new InkOverlaySelectionResizedEventHandler(inkOverlay_SelectionResized); inkOverlay.Enabled = true; myRecognizer = new RecognizerContext(); myRecognizer.Strokes = inkOverlay.Ink.CreateStrokes(); edgeTimer = new System.Timers.Timer(TIME_INTERVAL); edgeTimer.AutoReset = true; edgeTimer.Elapsed +=new ElapsedEventHandler(edgeTimer_Elapsed); edgeTimer.Enabled = true; }
/// <summary> /// Initializes a new instance of the <see cref="WritingRecognition"/> class. /// </summary> /// <param name="control">The control.</param> /// <param name="culture">The culture.</param> public WritingRecognition(Control control, CultureInfo culture) { foreach (Recognizer reco in _recognizers) for (int c = 0; c < reco.Languages.Length; c++) if (reco.Languages[c] == culture.LCID) { _context = reco.CreateRecognizerContext(); break; } if (_context == null) { MessageBox.Show(culture.DisplayName + " handwriting recognition support isn't installed on this Windows.", "Rincevent", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } _inkOverlay = new InkOverlay(control, true); _inkOverlay.Enabled = true; _strokes = _inkOverlay.Ink.CreateStrokes(); _context.Strokes = _strokes; _inkOverlay.Stroke += inkOverlay_Stroke; _inkOverlay.DefaultDrawingAttributes.AntiAliased = true; _inkOverlay.DefaultDrawingAttributes.Color = Color.DarkViolet; _inkOverlay.DefaultDrawingAttributes.FitToCurve = true; _context.RecognitionWithAlternates += context_RecognitionWithAlternates; }
//Recognizes the stroke private void recogClick(object sender, EventArgs e) { if (inkCanvas.Strokes.Count > 0) { StrokeCollection strokeList = inkCanvas.Strokes; //save the strokes MemoryStream ms = new MemoryStream(); inkCanvas.Strokes.Save(ms); InkCollector collector = new InkCollector(); Ink ink = new Ink(); ink.Load(ms.ToArray()); try { context = new RecognizerContext(); RecognitionStatus status; RecognitionResult result; context.Strokes = ink.Strokes; result = context.Recognize(out status); if (result.TopString == levelStr) { resultStr = "WON"; resultSplash = new ResultSplashScreen(); resultSplash.Show(); Thread.Sleep(1000); resultSplash.Close(); MessageBoxResult diagRes = MessageBox.Show("Do you want to proceed?\nYes to Proceed\nNo to Try Again", "important", MessageBoxButton.YesNo, MessageBoxImage.Question); //Change theme, if colorblind and progress to new level if (diagRes == MessageBoxResult.Yes) { write.Hide(); //Create a method that says "solved" after each level on the button //xxxxxxxx if (isColorBlind == true) { write.updateLevelProgress(); write.newLevel(isColorBlind); write.saveLevelProgress(levelStr); } else { write.updateLevelProgress(); write.newLevel(isColorBlind); write.saveLevelProgress(levelStr); } } //Otherwise, repeat the level else if (diagRes == MessageBoxResult.No) { if (isColorBlind == true) { write.repeatLevel(isColorBlind); } else { write.repeatLevel(isColorBlind); } } } else { resultStr = "LOSE"; resultSplash = new ResultSplashScreen(); resultSplash.Show(); Thread.Sleep(1000); resultSplash.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //Clear strokes after every try inkCanvas.Strokes.Clear(); } else { MessageBox.Show("Nothing"); } }
private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) { using (var frame = e.FrameReference.AcquireFrame()) { if (frame != null) { frame.GetAndRefreshBodyData(_bodies); Body body = _bodies.Where(b => b.IsTracked).FirstOrDefault(); if (body != null) { Joint handRight = body.Joints[JointType.HandRight]; if (handRight.TrackingState != TrackingState.NotTracked) { CameraSpacePoint handRightPosition = handRight.Position; ColorSpacePoint handRightPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(handRightPosition); float x = handRightPoint.X; float y = handRightPoint.Y; if (!float.IsInfinity(x) && !float.IsInfinity(y)) { if (body.HandRightState == HandState.Lasso) { KinectMouseMethods.SendMouseInput((int)x, (int)y, (int)trail.Width, (int)trail.Height, true); } if (body.HandRightState == HandState.Open) { KinectMouseMethods.SendMouseInput((int)x, (int)y, (int)trail.Width, (int)trail.Height, false); } if (body.HandRightState == HandState.Closed) { KinectMouseMethods.SendMouseInput((int)x, (int)y, (int)trail.Width, (int)trail.Height, false); using (MemoryStream ms = new MemoryStream()) { trail.Strokes.Save(ms); var myInkCollector = new InkCollector(); var ink = new Ink(); ink.Load(ms.ToArray()); using (RecognizerContext context = new RecognizerContext()) { if (ink.Strokes.Count > 0) { context.Strokes = ink.Strokes; RecognitionStatus status; var result = context.Recognize(out status); if (status == RecognitionStatus.NoError) { if (result.TopString == "&" || result.TopString == "&") { textBox.Text += " "; } else if (result.TopString == "|" && textBox.Text != "") { textBox.Text = textBox.Text.Remove(textBox.Text.Length - 1); } else { textBox.Text += result.TopString; } } } } } trail.Strokes.Clear(); } } } } } } }