简体   繁体   English

通过Cordova的Windows UWP应用程序:将画布转换为Javascript中的InkRecognizer的流

[英]Windows UWP apps via Cordova: convert canvas into stream for InkRecognizer in Javascript

I'm developing an application in Cordova for Android and Windows and struggle with the recogniztion of the text and numbers in canvas element on Windows platform (W10) 我正在用Cordova开发适用于Android和Windows的应用程序,并且难以识别Windows平台(W10)上的canvas元素中的文本和数字

So last couple of days I've wasted my time trying to use the Windows.Media.OCR namespace for the recognition of the handwritten numbers on my HTML5 canvas scribble pad as you can see here on another SO question 所以最近几天,我浪费了时间尝试使用Windows.Media.OCR命名空间来识别HTML5画布涂鸦板上的手写数字,正如您在此处看到的另一个SO问题

I've then found the Windows.UI.Input.Inking namespace and there are few classes available for the Javascript solutions. 然后,我找到了Windows.UI.Input.Inking命名空间,并且几乎没有可用于Javascript解决方案的类。 I've found there is an InkManager that can recognize InkStrokes either in its own collection or strokes in InkRecognizerContainer. 我发现有一个InkManager可以识别自己的集合中的InkStrokes或InkRecognizerContainer中的笔画。

InkRecognizerContainer has the "loadAsync()" method that accepts the input stream. InkRecognizerContainer具有接受输入流的“ loadAsync()”方法。 So I've thought I'd just load the canvas converted to stream, and use the InkManager to recognize this container. 因此,我认为我只是将转换后的画布加载为流,并使用InkManager识别此容器。

Unfortunately, if I try to use the HTML5 canvas converted to stream it throws me "WIN RT: Unsepcified Error" but not in the callbacks, it just crashes the app. 不幸的是,如果我尝试使用转换后的HTML5 canvas进行流传输,则会抛出“ WIN RT:Unsepcified Error”(WIN RT:未归类错误),但不会在回调中出现,这只会使应用程序崩溃。

var blob = canvas.msToBlob();
 var randomAccessStream = blob.msDetachStream();

 var inkStrokeContainer = new Windows.UI.Input.Inking.InkStrokeContainer();
 inkStrokeContainer.loadAsync(randomAccessStream).done(function () {
     debugger
 }, function (error) {
    console.log(error);
 });

Any help would be greatly appreciated as I'm spending way too much time on this. 任何帮助将不胜感激,因为我在此上花了太多时间。

InkStrokeContainer.LoadAsync requires a file with ink stroke information, not an arbitrary bitmap. InkStrokeContainer.LoadAsync需要包含墨水笔划信息的文件,而不是任意位图。 Generally this will be an ISF (Ink Serialized Format) file saved out from a previous InkStrokeContainer. 通常,这是从以前的InkStrokeContainer中保存的ISF(墨水序列化格式)文件。 ISF files include stroke information as metadata in a gif file, so they can be displayed by normal gif viewers, but typical gif files do not include ISF data and cannot load into InkStrokeContainers. ISF文件将笔划信息作为元数据包含在gif文件中,因此普通的gif查看器可以显示它们,但是典型的gif文件不包含ISF数据,因此无法加载到InkStrokeContainers中。

InkManager does handwriting recognition not OCR. InkManager不会执行手写识别,而不会执行OCR。 It requires individual stroke information and takes into account properties such as stroke order and direction. 它需要单独的笔划信息,并考虑了笔划顺序和方向等属性。 To use it you'll need to pass pointer information to the InkManager, typically as the input occurs, so the InkManager can build the strokes to recognize. 要使用它,您通常需要在输入发生时将指针信息传递给InkManager,以便InkManager可以构建笔画以进行识别。

Take a look at the Simplified Ink Sample for an example. 简化墨水样本为例。 The JavaScript version uses WinJS rather than Cordova, but it shouldn't be too hard to convert. JavaScript版本使用WinJS而不是Cordova,但是转换起来并不难。 The inking is Windows specific, so you'll need to put this in a platform specific part of your app. 墨迹特定于Windows,因此您需要将其放入应用程序特定于平台的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM