我嘗試開發離子應用程序,我想添加光學字符識別(OCR)。Ionic - OCR:ReferenceError TesseractPlugin未定義
我有安裝科爾多瓦相機插件,我想利用這個GitHub的項目(正方體):https://github.com/gustavomazzoni/cordova-plugin-tesseract
但是,當我使用這個功能,我有以下的錯誤在我的JavaScript控制檯:
ionic.bundle.js:26799 ReferenceError: TesseractPlugin is not defined
以下命令顯示:cordova plugin list
:
cordova-plugin-camera 2.3.1 "Camera"
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);
});
};
});
我沒有看到我的錯誤。
你是否解決了這個問題? – VLR