Tesseract always saying image is "Bad Base-64"
Hi, I have installed the plugin in an App for Android made with Ionic Framework. I am trying to get an image with cordova-image-camera which is getting a base64 image, which is correct (if I use it in an <IMG src=""> it show the image correctly). I pass that base64 as imageData input, but Tesseract always get an Exception "Bad Base-64". Do you what could be the reason?
Example code:
try {
TesseractPlugin.loadLanguage('ita', function(response) {
debugLog('Loading OCR language successful');
}, function(reason) {
debugLog('Error on loading OCR file for your language. ' + reason);
});
var _testImage ="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAANCAIAAAArLKlOAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABvSURBVChTpZBRFgARCEWty4JaT6tpMxbTiITDOI25X9S7QuArfmsJY1CAtCbUesSk+4JpBK1DYKIsI1IW37SOHD+llsJOqxPG0FmTfGF6WsY1rf7BqPq0JXbQcqsN+DSthBXL2HMVa+wu6eBKY34AAZZMtGg8cLgAAAAASUVORK5CYII=";
TesseractPlugin.recognizeText(_testImage , 'ita', function(recognizedText) {
debugLog("Tesseract recognized text: " + recognizedText);
}, function(error) {
debugLog('Error recognizing text from image: ' + error);
});
}
catch(e) {
debugLog("Tesseract Error: " + objToString(e.message) );
}
The loadLanguage() call works successfully. The recognizeText() always returns the function(reason), with the message: "Bad Base-64";
Thankyou. Carlo
I'm also getting the same error. Any update?
I was passing the wrong option to the Camera Plugin.
It should be cameraOptions.DestinationType.DATA_URL
@carlo318 in your case, pass the _testImage without prefixing it with data:image/jpep:base64,
and that should be it
I tried your suggestion @NBAMj , but now it does'nt give me any feedback, neither successful, nor failed.
With or without the prefix data:image/jpeg:base64,
How comes?
I also put try catch outside Tesseract and inside any function (successful or failed), but nothing happens. Could it be any issue with Java? The last version is always 0.0.1?
Thankyou.
Any resolution to this? I am getting same issue.
I resolve the problem like this:
var myimage = document.getElementById('smallImage').src.replace('data:image/jpeg;base64,', '');
TesseractPlugin.recognizeText(myimage, 'eng', function(recognizedText) {
console.log(recognizedText);
}, function(reason) {
console.log('Error on recognizing text from image. ' + reason);
});