数学试题识别
请求Header:
| 名称 | 值 | |
|---|---|---|
| Content-Type | application/x-www-form-urlencoded |
请求参数说明:
| 名称 | 必填 | 类型 | 说明 | |
|---|---|---|---|---|
| key | 是 | String | 在个人中心->我的数据,接口名称上方查看 | |
| image_base64 | 是 | String | 图片的 Base64 值。支持的图片格式:PNG、JPG、JPEG,暂不支持 GIF 格式。支持的图片大小:所下载图片经Base64编码后不超过 3M。 |
请求代码示例:
curl -k -i -d "key=key&image_base64=xxx" "https://apis.juhe.cn/edu_paper_ocr/query"
<?php
/**
* 1437-数学试题识别 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/edu_paper_ocr/query"; // 接口请求URL
$method = "POST"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'image_base64'=> 'xxx',
];
$requestParamsStr = http_build_query($requestParams);
// 发起接口网络请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$" . $apiUrl, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestParamsStr);
$response = curl_exec($curl);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// 解析响应结果
$responseResult = json_decode($response, true);
if ($responseResult) {
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
var_dump($responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
// var_dump($httpInfo);
var_dump("请求异常");
}
import requests
# 1437-数学试题识别 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/edu_paper_ocr/query' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'image_base64': 'xxx',
}
# 发起接口网络请求
response = requests.post(apiUrl, requestParams)
# 解析响应结果
if response.status_code == 200:
responseResult = response.json()
# 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
print(responseResult)
else:
# 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
print('请求异常')
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
)
func main() {
// 基本参数配置
apiUrl := "https://apis.juhe.cn/edu_paper_ocr/query"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("image_base64", "xxx")
// 发起接口网络请求
resp, err := http.Post(apiUrl, "application/x-www-form-urlencoded", strings.NewReader(requestParams.Encode()))
if err != nil {
fmt.Println("网络请求异常:", err)
return
}
defer resp.Body.Close()
var responseResult map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseResult)
if err != nil {
fmt.Println("解析响应结果异常:", err)
return
}
fmt.Println(responseResult)
}
using System;
using System.Text;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Specialized;
namespace Common_API_Test.Test_Demo
{
class Csharp_post
{
static void Main(string[] args)
{
string url = "https://apis.juhe.cn/edu_paper_ocr/query";
string apiKey = "您申请的调用APIkey";
using (WebClient client = new WebClient())
{
var data = new NameValueCollection();
// 添加元素到 NameValueCollection
data.Add("key", apiKey);
data.Add( "image_base64", "xxx");
try
{
byte[] response = client.UploadValues(url, "POST", data);
string responseContent = Encoding.UTF8.GetString(response);
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
if (responseData != null)
{
Console.WriteLine("Return Code: " + responseData["error_code"]);
Console.WriteLine("Return Message: " + responseData["reason"]);
}
else
{
Console.WriteLine("json解析异常!");
}
}
catch (Exception)
{
Console.WriteLine("请检查其它错误");
}
}
}
}
}
const axios = require('axios'); // npm install axios
// 基本参数配置
const apiUrl = 'https://apis.juhe.cn/edu_paper_ocr/query'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
image_base64: 'xxx',
};
// 发起接口网络请求
axios.post(apiUrl, requestParams, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(response => {
// 解析响应结果
if (response.status === 200) {
const responseResult = response.data;
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
console.log(responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
console.log('请求异常');
}
})
.catch(error => {
// 网络请求失败,可以根据实际情况进行处理
console.log('网络请求失败:', error);
});
package cn.juhe.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaPost {
public static void main(String[] args) throws Exception {
String apiKey = "你申请的key";
String apiUrl = "https://apis.juhe.cn/edu_paper_ocr/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("image_base64", "xxx");
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
String urlParameters = params(map);
try (OutputStream os = connection.getOutputStream()) {
byte[] input = urlParameters.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 打印响应
System.out.println(response);
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}
// 基本参数配置
NSString *apiUrl = @"https://apis.juhe.cn/edu_paper_ocr/query"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"image_base64": @"xxx",
};
// 将请求参数转换成字符串形式
NSMutableString *postString = [NSMutableString string];
[requestParams enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[postString appendFormat:@"%@=%@&", key, value];
}];
[postString deleteCharactersInRange:NSMakeRange(postString.length - 1, 1)]; // 删除最后一个"&"
// 发起接口网络请求
NSURL *url = [NSURL URLWithString:apiUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
request.HTTPBody = [postString dataUsingEncoding:NSUTF8StringEncoding]; // 设置HTTPBody为转换后的参数字符串
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// 网络请求异常处理
NSLog(@"请求异常");
} else {
NSError *jsonError;
NSDictionary *responseResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (!jsonError) {
// 网络请求成功处理
NSLog(@"%@", [responseResult objectForKey:@"error_code"]);
NSLog(@"%@", [responseResult objectForKey:@"reason"]);
NSLog(@"%@", responseResult);
} else {
// 解析结果异常处理
NSLog(@"解析结果异常");
}
}
}];
[task resume];
返回参数说明:
| 名称 | 类型 | 说明 | |
|---|---|---|---|
| error_code | Integer | 状态码,成功时返回0 | |
| reason | String | 状态信息 | |
| result | Object | 返回结果 | |
| result.request_id | String | 请求 ID | |
| result.edu_paper_infos | Array of TextEduPaper | 检测到的文本信息 | |
| TextEduPaper.detected_text | String | 识别出的文本行内容 | |
| result.question_block_infos | Array of QuestionBlockObj | 结构化方式输出 | |
| QuestionBlockObj.question_arr | Array of QuestionObj | 数学试题识别结构化信息数组 | |
| QuestionObj.question_text_no | String | 题号 | |
| QuestionObj.question_text_type | Integer | 题型:1: 选择题,2: 填空题,3: 解答题 | |
| QuestionObj.question_text | String | 题干 | |
| QuestionObj.question_options | String | 选择题选项 | |
| QuestionObj.question_sub_question | String | 所有子题的question属性 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "success",
"result": {
"request_id": "0baa0eb5-5a4b-4724-9c85-e918059b2355",
"edu_paper_infos": [
{
"detected_text": "f ( x ) = \\frac { a x + 1 } { x + 2 } "
},
{
"detected_text": "\\frac { f ( x _ { 1 } ) - f ( x _ { 2 } ) } { x _ { 1 } - x _ { 2 } } < 0 "
},
{
"detected_text": "C . \\quad \\lbrack \\frac { 1 } { 3 } , \\frac { 1 } { 2 } ) "
},
{
"detected_text": "A . \\quad ( 0 , \\frac { 1 } { 2 } ) "
},
{
"detected_text": "D . \\quad ( \\frac { 1 } { 2 } , 1 ) "
},
{
"detected_text": "C . \\quad \\lbrack \\frac { 1 } { 4 } , 1 ) "
},
{
"detected_text": "A . \\quad ( 0 , \\frac { 1 } { 4 } \\rbrack "
},
{
"detected_text": "f ( x ) = \\left\\lbrace\\begin{array}{l} { a ^ { x } , } & { x < 0 } \\\\ { ( a - 3 ) x + 4 a , x \\geq 0 } \\end{array}\\right. "
},
{
"detected_text": "f ( x ) = \\left\\lbrace\\begin{array}{l} { ( 2 a - 1 ) x + a , x \\geq 1 } \\\\ { \\log _ a x } & { x < 1 } \\end{array}\\right. "
},
{
"detected_text": "B . \\quad ( 0 , \\frac { 1 } { 3 } \\rbrack "
},
{
"detected_text": "x _ { 1 } \\neq x _ { 2 } "
},
{
"detected_text": "题型4:已知函数的单调性求参数的取值范围"
},
{
"detected_text": "[例9] (★★★) 已知函数"
},
{
"detected_text": "在区间(-2, +∞)上是增函数,试求a的取值范围."
},
{
"detected_text": "[例10] (★★★★) 已知函数,若"
},
{
"detected_text": "在(0, +∞)上单调递减,则a的取"
},
{
"detected_text": "值范围为( )"
},
{
"detected_text": "[例11] (★★★★★)设 "
},
{
"detected_text": ",对任意的."
},
{
"detected_text": "都有"
},
{
"detected_text": "成立,"
},
{
"detected_text": "则a的取值范围是( )"
},
{
"detected_text": "B. (0, 1)"
},
{
"detected_text": "D. (0,3)"
},
{
"detected_text": "2019年高三.数学.寒假文科 "
},
{
"detected_text": ""
},
{
"detected_text": ""
}
],
"question_block_infos": [
{
"question_arr": [
{
"question_text_no": "",
"question_text_type": 3,
"question_text": "题型4:已知函数的单调性求参数的取值范围",
"question_options": "[{\"option\":[]}]",
"question_sub_question": "[]"
}
]
},
{
"question_arr": [
{
"question_text_no": "[例9]",
"question_text_type": 3,
"question_text": "(★★★)已知函数f(x)=\\frac{ax+1}{x+2}在区间(-2,+∞)上是增函数,试求a的取值范围.",
"question_options": "[{\"option\":[]}]",
"question_sub_question": "[]"
}
]
},
{
"question_arr": [
{
"question_text_no": "[例10]",
"question_text_type": 1,
"question_text": "(★★★★)已知函数,若f(x)=\\left\\lbrace\\begin{array}{l}{(2a-1)x+a,x\\geq1}\\\\{\\log_ax}&{x<1}\\end{array}\\right.在(0,+∞)上单调递减,则a的取值范围为##{()}##",
"question_options": "[{\"option\":[\"$${\\\\quad(0,\\\\frac{1}{2})}$$\",\"$${\\\\quad(0,\\\\frac{1}{3}\\\\rbrack}$$\",\"$${\\\\quad\\\\lbrack\\\\frac{1}{3},\\\\frac{1}{2})}$$\",\"$${\\\\quad(\\\\frac{1}{2},1)}$$\"]}]",
"question_sub_question": "[]"
}
]
},
{
"question_arr": [
{
"question_text_no": "[例11]",
"question_text_type": 1,
"question_text": "(★★★★★)设f(x)=\\left\\lbrace\\begin{array}{l}{a^{x},}&{x<0}\\\\{(a-3)x+4a,x\\geq0}\\end{array}\\right.,对任意的.x_{1}\\neqx_{2}都有\\frac{f(x_{1})-f(x_{2})}{x_{1}-x_{2}}<0成立,则a的取值范围是##{()}##",
"question_options": "[{\"option\":[\"$${\\\\quad(0,\\\\frac{1}{4}\\\\rbrack}$$\",\"(0,1)\",\"$${\\\\quad\\\\lbrack\\\\frac{1}{4},1)}$$\",\"(0,3)\"]}]",
"question_sub_question": "[]"
}
]
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
| 错误码 | 说明 | |
|---|---|---|
| 252801 | 查询参数错误 | |
| 252802 | 请求失败 |
系统级错误码参照:
| 错误码 | 说明 | 旧版本(resultcode) | |
|---|---|---|---|
| 10001 | 错误的请求KEY | 101 | |
| 10002 | 该KEY无请求权限 | 102 | |
| 10003 | KEY过期 | 103 | |
| 10004 | 错误的OPENID | 104 | |
| 10005 | 应用未审核超时,请提交认证 | 105 | |
| 10007 | 未知的请求源 | 107 | |
| 10008 | 被禁止的IP | 108 | |
| 10009 | 被禁止的KEY | 109 | |
| 10011 | 当前IP请求超过限制 | 111 | |
| 10012 | 请求超过次数限制 | 112 | |
| 10013 | 测试KEY超过请求限制 | 113 | |
| 10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) | 114 | |
| 10020 | 接口维护 | 120 | |
| 10021 | 接口停用 | 121 |
错误码格式说明(示例:200201):
| 2 | 002 | 01 | |
|---|---|---|---|
| 服务级错误(1为系统级错误) | 服务模块代码(即数据ID) | 具体错误代码 |
接口文档下载
苏公网安备 32059002001776号