我使用OCR space API来获取我制作的Image上的文字,但我不知道为什么没有结果我不擅长java脚本,错误可能在其中
我认为如果有人知道问题,请写一切,请帮助我
我认为如果有人知道问题,请写一切,请帮助我 我想如果有人知道问题,请写一切,请帮助我 我想如果有人知道问题,请写一切,请帮助我 我想如果有人知道问题,请写一切,请帮助我 我想如果有人知道问题,请写一切,请帮助我 如果有人知道问题,我想每件事都是写的,请帮帮我
此链接上的代码http://codepad.org/iu1wd0PB
<form>
<input type="file" >
<div id="log"></div>
</form>
<script type="text/javascript" src="jquery-3.2.1.min.js">
$(':file').on('change', function() {
var file = this.files[0];
var formData = new FormData();
formData.append("file", file);
//formData.append("url", file);
formData.append("language" , "ara");
formData.append("apikey" , "ec5eeebb6288957");
formData.append("isOverlayRequired", true);
//Send OCR Parsing request asynchronously
jQuery.ajax({
url: "https://api.ocr.space/parse/image",
data: formData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (ocrParsedResult) {
//Get the parsed results, exit code and error message and details
var parsedResults = ocrParsedResult["ParsedResults"];
var ocrExitCode = ocrParsedResult["OCRExitCode"];
var isErroredOnProcessing = ocrParsedResult["IsErroredOnProcessing"];
var errorMessage = ocrParsedResult["ErrorMessage"];
var errorDetails = ocrParsedResult["ErrorDetails"];
var processingTimeInMilliseconds = ocrParsedResult["ProcessingTimeInMilliseconds"];
//If we have got parsed results, then loop over the results to do something
if (parsedResults!= null) {
//Loop through the parsed results
$.each(parsedResults, function (index, value) {
var exitCode = value["FileParseExitCode"];
var parsedText = value["ParsedText"];
console.log(parsedText);
var errorMessage = value["ParsedTextFileName"];
var errorDetails = value["ErrorDetails"];
var textOverlay = value["TextOverlay"];
var pageText = '';
switch (+exitCode) {
case 1:
pageText = parsedText;
console.log(pageText);
break;
case 0:
case -10:
case -20:
case -30:
case -99:
default:
pageText += "Error: " + errorMessage;
break;
}
console.log(pageText);
$.each(textOverlay["Lines"], function (index, value) {
/*..........................
..........................
..........................
LOOP THROUGH THE LINES AND GET WORDS TO DISPLAY ON TOP OF THE IMAGE AS OVERLAY
..........................
..........................
..........................*/
});
/*..........................
..........................
..........................
YOUR CODE HERE
..........................
..........................
..........................*/
});
}
}
});
// Also see .name, .type
});
</script>
答案 0 :(得分:0)
问题是你的代码有几个语法错误,所以我为你修复了它:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<form>
<input type="file" name="uploader">
</form>
<script type="text/javascript">
$(':file').on('change', function() {
var file = this.files[0];
var formData = new FormData();
formData.append("file", file);
//formData.append("url", file);
formData.append("language" , "ara");
formData.append("apikey" , "ec5eeebb6288957");
formData.append("isOverlayRequired", true);
//Send OCR Parsing request asynchronously
jQuery.ajax({
url: "https://api.ocr.space/parse/image",
data: formData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (ocrParsedResult) {
//Get the parsed results, exit code and error message and details
var parsedResults = ocrParsedResult["ParsedResults"];
var ocrExitCode = ocrParsedResult["OCRExitCode"];
var isErroredOnProcessing = ocrParsedResult["IsErroredOnProcessing"];
var errorMessage = ocrParsedResult["ErrorMessage"];
var errorDetails = ocrParsedResult["ErrorDetails"];
var processingTimeInMilliseconds = ocrParsedResult["ProcessingTimeInMilliseconds"];
//If we have got parsed results, then loop over the results to do something
if (parsedResults!= null) {
//Loop through the parsed results
$.each(parsedResults, function (index, value) {
var exitCode = value["FileParseExitCode"];
var parsedText = value["ParsedText"];
console.log(parsedText);
var errorMessage = value["ParsedTextFileName"];
var errorDetails = value["ErrorDetails"];
var textOverlay = value["TextOverlay"];
var pageText = '';
switch (+exitCode) {
case 1:
pageText = parsedText;
console.log(pageText);
break;
case 0:
case -10:
case -20:
case -30:
case -99:
default:
pageText += "Error: " + errorMessage;
break;
}
console.log(pageText);
$.each(textOverlay["Lines"], function (index, value) {
/*..........................
..........................
..........................
LOOP THROUGH THE LINES AND GET WORDS TO DISPLAY ON TOP OF THE IMAGE AS OVERLAY
..........................
..........................
..........................*/
});
/*..........................
..........................
..........................
YOUR CODE HERE
..........................
..........................
..........................*/
});
}
}
});
});
</script>
</body>
</html>