我尝试开发一个离子应用程序,我想添加一个光学字符识别(OCR)。
我已经安装了cordova相机插件,我想使用这个github项目(tesseract):https://github.com/gustavomazzoni/cordova-plugin-tesseract
但是,当我使用此功能时,我的javascript控制台出现以下错误:
ionic.bundle.js:26799 ReferenceError:未定义TesseractPlugin
以下命令显示:cordova plugin list
:
cordova-plugin-camera 2.3.1“相机”
cordova-plugin-compat 1.1.0“Compat”
cordova-plugin-tesseract 0.0.1“Tesseract Plugin”
phonegap-plugin-barcodescanner 6.0.5“BarcodeScanner”
这是我的控制器代码:
'Use Strict';
angular.module('App')
.controller('CameraOCRController', function($scope, $cordovaCamera) {
TesseractPlugin.loadLanguage(language, function(response) {
deferred.resolve(response);
}, function(reason) {
deferred.reject('Error on loading OCR file for your language. ' + reason);
});
$scope.takePhoto = function () {
var options = {
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function (imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
$scope.text = recognizedText;
}, function(reason) {
alert('Error on recognizing text from image. ' + reason);
});
}, function (err) {
alert("An error occured. Show a message to the user"+err);
});
};
});
我没有看到我的错误。
答案 0 :(得分:0)
在引用插件之前,您是否等待deviceready
触发?