gpt4 book ai didi

c# - 每次用户完成描笔后,如何进行手写识别?

转载 作者:行者123 更新时间:2023-11-30 21:53:39 25 4
gpt4 key购买 nike

基于 MSDN 为 Handwriting Recognition 提供的代码在 Windows 10 应用程序中,我尝试让它在用户完成笔划笔划后自动识别手写内容,而不是在单击按钮时自动识别。

当我的 Canvas 中触发 PointerReleased 事件时,通过调用我的手写识别方法,我已经能够在 Windows 8.1 Metro 应用程序中执行类似的操作。它运行良好,我尝试在 UWP 中模拟相同的行为。

PointerReleased 事件未在 UWP 应用程序中触发,因此我使用 InkCanvas.InkPresenter.StrokeInput.StrokeEnded 事件来调用此方法:

async void RecognizeAsync(InkStrokeInput input, PointerEventArgs e)
{
IReadOnlyList<InkStroke> currentStrokes =myInkCanvas.InkPresenter.StrokeContainer.GetStrokes();
if (currentStrokes.Count > 0)
{
var recognitionResults = await inkRecognizerContainer.RecognizeAsync(myInkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

if (recognitionResults.Count > 0)
{
// Display recognition result
string str = "Recognition result:";
foreach (var r in recognitionResults)
{
str += " " + r.GetTextCandidates()[0];
}
Status.Text=str;
}
else
{
Status.Text = "No text recognized.";
}
}
else
{
Status.Text="Must first write something.";
}
}

它接近我想要实现的目标,只是没有考虑最后一笔。我猜想当 StrokeEnded 事件被触发时,InkStroke 尚未被“处理”,因此它不包含在 currentStrokes 中。

我试图通过将事件的 InkStrokeInput 对应的 Strokes 添加到我用作识别参数的 StrokeContainer 来规避这个问题:

InkStrokeContainer totalStrokes=new InkStrokeContainer();
if (currentStrokes.Count > 0) {
totalStrokes= myInkCanvas.InkPresenter.StrokeContainer;
}
totalStrokes.AddStrokes(input.InkPresenter.StrokeContainer.GetStrokes());

var recognitionResults = await inkRecognizerContainer.RecognizeAsync(totalStrokes, InkRecognitionTarget.All);

但是 input.InkPresenter.StrokeContainer.GetStrokes() 返回一个空列表。

有没有办法让我在事件触发时访问当前的 Stroke?或者在笔划被“处理”后,我可以使用另一个事件来调用手写识别吗?或者另一种自动识别所有当前 InkStrokes 的笔迹的方法?

最佳答案

我找到了一种方法,通过在触发 InkCanvas.InkPresenter.StrokesCollected 事件时调用我的 RecognizedAsync 方法来实现我期望的结果。

来自 MSDN 文档:

InkPresenter.StrokesCollected event

Occurs when one or more ink strokes are processed ("wet" to "dry") by the >application thread.

By default, an ink stroke is processed on a low-latency background thread and >rendered wet as it is drawn. When the stroke is completed (pen or finger >lifted, or mouse button released), the stroke is processed on the UI thread >and rendered dry to the InkCanvas layer (above the application content).

关于c# - 每次用户完成描笔后,如何进行手写识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33738500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com