无法将图像数据用作OCR API的参数 [英] Unable to use Image data as a parameter to the OCR API

查看:57
本文介绍了无法将图像数据用作OCR API的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将图像数据用作OCR API的参数。我尝试了
测试控制台
以及jquery AJAX 。我得到400 Bad< g class =" gr_ gr_168 gr-alert gr_gramm undefined Grammar multiReplace"数据-GR-ID =" 168" id =" 168"> request< / g> 或无效的图片格式。可以
有人分享正确的请求吗?在将图像URL作为参数发送到API时,我能够恢复文本。来自测试控制台的带有Image二进制文件的任何样本或成功请求都将有用。



解决方案

这样的东西?

< html> 
< head>
< script src =" http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">< / script>
< script type =" text / javascript">
ocr = function(){
var f =


('#file-input')。get(0).files [0];

.ajax({
url:" http://api.projectoxford.ai/vision/v1/ocr" ;,
beforeSend:function(xhrObj){
//请求标头
xhrObj.setRequestHeader(" Content-Type"," application / octet-stream");
xhrObj.setRequestHeader(" Ocp-Apim-Subscription-Key", "YOUR-API-KEY");
},
类型:" POST",
//请求正文
数据:f,
processData:false
})
.done(函数(数据){
alert(" success");

//显示数据
console.log( JSON.stringify(data));
})
.fail(function(e){
alert(" error");
debugger;
});
}
< / script>
< / head>
< body>
< p>< input type =" file" ID = QUOT;文件输入与QUOT;><峰; br />
< button onclick =" ocr()"> ocr!< / button>
< / p>< / body>
< / html>




I am unable to use image data as a parameter to the OCR API. I tried with the testing console as well as the  jquery AJAX. I am getting 400 Bad <g class="gr_ gr_168 gr-alert gr_gramm undefined Grammar multiReplace" data-gr-id="168" id="168">request</g> or Invalid Image format. Can someone share the correct request for the  same? I am able to get the text back while sending the image URL as a parameter to the API. Any sample or successful request from testing console with the Image binaries will be Helpful.

解决方案

Something like this?

<html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script type="text/javascript">
	ocr = function() {
        var f =


('#file-input').get(0).files[0];


.ajax({ url: "http://api.projectoxford.ai/vision/v1/ocr", beforeSend: function(xhrObj){ // Request headers xhrObj.setRequestHeader("Content-Type","application/octet-stream"); xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","YOUR-API-KEY"); }, type: "POST", // Request body data: f, processData: false }) .done(function(data) { alert("success"); //display data console.log(JSON.stringify(data)); }) .fail(function(e) { alert("error"); debugger; }); } </script> </head> <body> <p><input type="file" id="file-input"><br/> <button onclick="ocr()">ocr!</button> </p></body> </html>



这篇关于无法将图像数据用作OCR API的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆