cordova-plugin-tesseract icon indicating copy to clipboard operation
cordova-plugin-tesseract copied to clipboard

Tesseract always saying image is "Bad Base-64"

Open carlo318 opened this issue 9 years ago • 5 comments

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

carlo318 avatar Dec 02 '16 17:12 carlo318

I'm also getting the same error. Any update?

NBAMj avatar Jun 12 '17 08:06 NBAMj

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

NBAMj avatar Jun 12 '17 11:06 NBAMj

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.

carlo318 avatar Jun 16 '17 15:06 carlo318

Any resolution to this? I am getting same issue.

ShailBag avatar Feb 12 '18 07:02 ShailBag

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);
});

rjurado01 avatar Feb 20 '20 11:02 rjurado01