12-01-2017 11:10 AM - edited 02-04-2024 1:30 AM
Hi Team,
We were testing this new API (Optical Character Recognition (OCR) API) based on OCR technology and have 2 queries based on functionality/usage.
1.) Its "Try It Out" functionality works for .PDF files and correctly list out the contents as response. But it doesnt behave the same way for .jpeg or png files. The overview details state that it should be behaving the same way for .jpg or .pdf files, but it is not happening correctly.
2.) We are trying to test its functionality from the web full stack ide using the ui5 generated code but are facing some api connectivity issues. We tried to check the connection from the destination created but that too doesnt happen successfully. Is there any specific mapping required to be done so that api could be used.
Regards,
SK
12-14-2017 4:13 AM
Hi SK,
I took screen shot and used the ".png" picture like this text.png and it worked fine.
I guess the accuracy would depend on the noises in the picture and could you try with the simple pictures with black characters and white background first?
About the destination, what kind of error did you face?
R
egards,
Makoto
12-20-2017 10:34 AM
Hi,
I have followed steps similar to blog https://www.sap.com/india/developer/tutorials/ml-fs-sapui5-img-classification.html
and in it as per step 4 i.e destination configuration, we can add details of the sandbox url and click on check connection. When I add it in my trial account, I get below message -Failure reason: "Could not check at the moment. Please try again later"
Kindly advise.
regards,
S.K.
12-14-2017 7:04 AM
Hi S.K.
you can use this code for getting ocr work
getOCR: function(oEvent) {
var sHeaders = {
"Accept": "application/json",
"APIKey": "Your api key"
};
var url = "";
var data = new FormData();
// this is file object
data.append('file', this.getView().byId("fileUploader").getFocusDomRef().files[0]);
data.append('lang', "en");
data.append('output_type', 'txt');
this.webRequest(data,sHeaders,this.onOCRDetectedSuccess.bind(this),this.onOCRDetectedFailed);
},
onOCRDetectedSuccess: function(data) {
console.log(data);
},
onOCRDetectedFailed: function() {
},
webRequest:function(data,header,successcallback,failcallback){
var ajaxRequest = {};
ajaxRequest.url = /SAP_Leonardo_ML/ocr/ocr;
ajaxRequest.method = "POST";
ajaxRequest.headers = header;
ajaxRequest.data = data;
ajaxRequest.processData = false;
ajaxRequest.contentType = false;
ajaxRequest.cache = false;
ajaxRequest.success = successcallback.bind(this);
ajaxRequest.error = failcallback.bind(this);
jQuery.ajax(ajaxRequest);
},
12-20-2017 12:13 PM
Hi,
I will try this code and let you know.
thanks for your help.
regards,
SK
01-19-2018 3:47 PM
Hi there!
I was trying to use this API but it even doesnt work for PDF files. I tried a lot but I dont understand why it isnt working. I always get the http error 400(Bad Request). Maybe somebody of you can help me. That would be great!
That is my controller:
return Controller.extend("OCR.controller.view", {
handleUploadPress: function(oEvent) {
var oFileUploader = this.getView().byId("fileUploader");
if (!oFileUploader.getValue()) {
sap.m.MessageToast.show("Choose a file first");
return;
}
var that = this;
var f = document.querySelector('input[type="file"]').files[0];
//Create form object and append file to the same
var data = new FormData();
data.append('files', document.getElementById("__xmlview0--fileUploader-fu").files[0], document.getElementById(
"__xmlview0--fileUploader-fu").files[0].name);
data.append('lang', "en");
data.append('output_type', 'txt');
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
//var vjson = JSON.parse(this.responseText);
that.getView().byId("JSONText").setText(this.responseText);
//var label = vjson.predictions[0].results[0].label;
//var score = vjson.predictions[0].results[0].score;
}
});
xhr.open("POST", "https://sandbox.api.sap.com/ml/ocr/ocr");
// xhr.open("POST", "https://sandbox.api.sap.com/ml/imageclassifier/inference_sync");
xhr.setRequestHeader("APIkey", "----------------------------");
xhr.setRequestHeader("Accept", "application/json");
xhr.send(data);
}
});
07-11-2018 7:30 AM
Hi SK,
I am trying the same OCR concept and I get the same 400 Error. Were you able to solve this??
If so, kindly share the code.
Regards,
Ramya