我有一个cordova项目,在那里我有一个"scribble pad“,用户可以在那里涂鸦他们的笔记。这是一个简单的画布对象,我想让OCR Engine将其转换为文本。我正在努力将画布数据转换成OCR引擎支持的软件位图。
所有样本都基于从存储中加载文件或从摄像头读取流。我是否必须将此画布保存到设备上的文件中,并将其读回流中?
我很欢迎这里的指导,因为图像是我努力解决的问题。
更新
因此,我设法获得了流,但不幸的是,OCR无法识别它。
我有画布对象,在页面加载后,我将文本放入其中,因此任何有能力的OCR都应该能够读取它。我还有"img“元素,用于检查流是否正确以及是否包含正确的位图。下面是将convas转换为OCR识别的代码
var blob = canvas.msToBlob();
// This is the stream I'll use for OCR detection
var randomAccessStream = blob.msDetachStream();
// This is the stream I'll use for the image element to make sure the stream above contains what I've placed into the canvas
var blob2 = MSApp.createBlobFromRandomAccessStream("image/png", randomAccessStream.cloneStream());
// Angular JS scope model
$scope.imageUrl = URL.createObjectURL(blob2);
// This works, but returns ""
var scope = this;
if (!this.ocrEngine)
return;
var bitmapDecoder = Windows.Graphics.Imaging.BitmapDecoder;
bitmapDecoder.createAsync(randomAccessStream).then(function (decoder) {
return decoder.getSoftwareBitmapAsync();
}).then(function (bitmap) {
return scope.ocrEngine.recognizeAsync(bitmap);
}).then(function (result) {
console.log(result.text);
});
在这一切运行之后,图像将被赋予src,并被加载并包含画布中的所有内容,因此流是正确的。
ocrEngine的设置方式如下:
var Globalization = Windows.Globalization;
var OCR = Windows.Media.Ocr;
this.ocrEngine = OCR.OcrEngine.tryCreateFromUserProfileLanguages();
if (!this.ocrEngine) {
// Try to create OcrEngine for specified language.
// If language is not supported on device, method returns null.
this.ocrEngine = OCR.OcrEngine.tryCreateFromLanguage(new Globalization.Language("en-us"));
}
if (!this.ocrEngine) {
console.error("Selected language is not available.");
}
为什么OCR不能识别简单的“Hello World”?
发布于 2016-03-13 06:49:40
好吧,这是相当尴尬的是,意识到OCR无法读取任何东西的原因,即使是系统写入的文本也是如此,因为生成的图像具有透明的背景。一旦我包含了一个带有白色填充的矩形,所有的一切都开始正常工作。
不幸的是,OCR很难识别我在画布上涂鸦的任何东西,因此无法识别画布中的手写数字或多行文本,请参见下面的内容
公认的:
无法识别
无法识别:
无法识别:
然后我找到了Windows.UI.Input.Inking命名空间,我认为这是唯一的选择。
https://stackoverflow.com/questions/35954842
复制相似问题