Reputation: 838
I try to develop an ionic app and I would like add an optical character recognition (OCR).
I have install the cordova camera plugin and I would like use this github project (tesseract): https://github.com/gustavomazzoni/cordova-plugin-tesseract
But, when I use this function, I have the following error into my javascript console :
ionic.bundle.js:26799 ReferenceError: TesseractPlugin is not defined
The following command display : 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"
Here is my controller code :
'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);
});
};
});
I don't see my error.
Upvotes: 0
Views: 892
Reputation: 3550
Do you wait for deviceready
to fire before referencing the plugin?
Upvotes: 0