python拍照搜题_OCR拍照搜题
OCR拍照搜題
簡(jiǎn)介
HI,您好,歡迎使用學(xué)而思網(wǎng)校AI開放平臺(tái)OCR拍照搜題接口服務(wù)。
本文檔主要針對(duì)需要集成HTTP API的技術(shù)研發(fā)工程師,詳細(xì)描述OCR拍照搜題能力相關(guān)的技術(shù)內(nèi)容。您可以通過(guò)
接口能力
接口名稱
接口能力簡(jiǎn)要描述
api 地址
OCR拍照搜題
檢測(cè)上傳圖像中的文字,進(jìn)行 AI 文字識(shí)別,然后搜索相關(guān)的試題。
http://openapiai.xueersi.com/v1/api/img/ocr/photo_search
適用范圍
任意操作系統(tǒng),任意編程語(yǔ)言,均可以通過(guò)http或https調(diào)用本接口。
圖像發(fā)送方式
圖像數(shù)據(jù)支持兩種形式發(fā)送:
URL
網(wǎng)絡(luò)上的圖片 URL 地址
圖片數(shù)據(jù)
請(qǐng)求圖片需經(jīng)過(guò)base64編碼:圖片的base64編碼指將一副圖片編碼成字符串?dāng)?shù)據(jù),便于網(wǎng)絡(luò)傳輸請(qǐng)求。您可以首先得到圖片的二進(jìn)制,進(jìn)行base64編碼后,然后再進(jìn)行urlencode(注意你所使用的網(wǎng)絡(luò)工具或網(wǎng)絡(luò)庫(kù)有沒有默認(rèn)的urlencode功能,如果沒有,需要你自己顯式轉(zhuǎn)化)。
轉(zhuǎn)碼方式可參考
注意: 圖片的base64編碼是不包含圖片頭的,如(data:image/jpg;base64,)
圖片大小
不能大于4MB
長(zhǎng)邊不能超過(guò)4096px
短邊不能小于15px
圖像類型支持
圖像數(shù)據(jù)支持以下原生類型:
jpg
png
jpeg
bmp
文字識(shí)別范圍
目前,OCR識(shí)別接口服務(wù)支持多種類型文字,包括:
中文打印體識(shí)別
英文打印體識(shí)別
表格識(shí)別
拼音識(shí)別
請(qǐng)求方式
HTTP 方法:POST
請(qǐng)求 URL:http://openapiai.xueersi.com/v1/api/img/ocr/photo_search
注意: Content-Type為application/x-www-form-urlencoded,然后通過(guò)urlencode格式化請(qǐng)求體。
Header 如下:
參數(shù)名
賦值
Content-Type
application/x-www-form-urlencoded
urlencode介紹
在請(qǐng)求 API 的 post 請(qǐng)求參數(shù)中含有圖片url地址或base64字符。url地址 或 base64 字符作為參數(shù)傳遞時(shí),需要把 中文 以及 '/' 做一下編碼,防止解析中出現(xiàn)歧義,從而符合url的規(guī)范。
將中文 以及 '/' ?轉(zhuǎn)換為百分號(hào)編碼形式,這就是 urlencode格式化操作。
部分語(yǔ)言的第三方包內(nèi)部做了 urlencode 編碼,不進(jìn)行 urlencode 格式化也可以正常進(jìn)行 API 請(qǐng)求,但 ? ?是進(jìn)行 urlencode 格式化之后,一定可以通過(guò)請(qǐng)求。所以我們推薦您對(duì)請(qǐng)求體中的參數(shù)進(jìn)行 urlencode 操作。
快速接入方式
請(qǐng)求參數(shù)詳情
參數(shù)名
類型
是否必選
賦值說(shuō)明
樣例
備注
app_key
string
是
應(yīng)用標(biāo)識(shí)
8102b22a5e81e840176d9f381ec6f837
img
string
是
圖像數(shù)據(jù)
https://i.loli.net/2019/03/22/5c94684fad743.jpg
或
圖像 base64數(shù)據(jù):示例數(shù)據(jù)較長(zhǎng),見附件
圖像base64字符串 / 圖像URL
img_type
string
是
圖像形式
URL
base64 / URL
subject_id
integer
否
學(xué)科id
1:語(yǔ)文,2:數(shù)學(xué),3:英語(yǔ),4:物理,5:化學(xué),6:生物,7:政治,8:歷史,9:地理,20:趣味,21:科學(xué),25:生化,26:編程,44:人文
默認(rèn)0
請(qǐng)求代碼示例
HTTP 代碼示例:
POST /v1/api/img/ocr/photo_search HTTP/1.1
Host: openapiai.xueersi.com
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3a%2f%2fi.loli.net%2f2019%2f03%2f22%2f5c94684fad743.jpg&img_type=URL
cURL 代碼示例:
curl -X POST \
http://openapiai.xueersi.com/v1/api/img/ocr/photo_search \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3a%2f%2fi.loli.net%2f2019%2f03%2f22%2f5c94684fad743.jpg&img_type=URL'
PHP 代碼示例:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3a%2f%2fi.loli.net%2f2019%2f03%2f22%2f5c94684fad743.jpg&img_type=URL",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Python(Python3) 代碼示例:
URL傳參方式:
import http.client
conn = http.client.HTTPConnection("openapiai.xueersi.com")
payload = "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
conn.request("POST", "/v1/api/img/ocr/photo_search/", payload, headers)
res = conn.getresponse()
data = res.read()
#python2.7
#print(data)
#python3.6
print(data.decode("utf-8"))
conn.close()
base64傳參方式:
import http.client
import urllib
import base64
from urllib import quote
with open('./test.jpg', 'rb') as bin_data:
image_data = bin_data.read()
image_data_base64 = base64.b64encode(image_data)
image_data_base64 = quote(image_data_base64)
conn = http.client.HTTPConnection("openapiai.xueersi.com")
appkey_string = 'app_key=8102b22a5e81e840176d9f381ec6f837'
img_string = 'img=' + image_data_base64
img_type_string = 'img_type=base64'
payload = appkey_string + '&' + img_string + '&' + img_type_string
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
conn.request("POST", "/v1/api/img/ocr/photo_search/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
conn.close()
C++(LibCurl) 代碼示例:
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "cache-control: no-cache");
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3a%2f%2fi.loli.net%2f2019%2f03%2f22%2f5c94684fad743.jpg&img_type=URL");
CURLcode ret = curl_easy_perform(hnd);
Java 代碼示例:
public static void QuickConnect(){
new Thread(new Runnable() {
@Override
public void run() {
try {
Map params = new HashMap();
params.put("app_key", "8102b22a5e81e840176d9f381ec6f837");
params.put("img","https://i.loli.net/2019/03/22/5c94684fad743.jpg");
params.put("img_type","URL");
Log.i(TAG,"start post");
String result = HttpUtil.sendPostMessage(params,"utf-8");
System.out.println("result->"+result);
}catch(Exception e)
{
e.printStackTrace();
}
}
}).start();
}
JavaScript 代碼示例:
var settings = {
"async": true,
"crossDomain": true,
"url": "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
},
"data": {
"app_key": "8102b22a5e81e840176d9f381ec6f837",
"img": "https://ai.xueersi.com/textRecognition/images/22.jpg",
"img_type": "URL"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Go 代碼示例:
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search"
payload := strings.NewReader("app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
C# 代碼示例:
using System;
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string celerityPost = CelerityPost();
Console.WriteLine("快速接入方式:\n" + celerityPost);
Console.ReadLine();
}
private static string CelerityPost()
{
string url = "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search";//URL地址
string payload = "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL";
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentLength = Encoding.UTF8.GetByteCount(payload);
webRequest.ContentType = "application/x-www-form-urlencoded";//Content-Type
webRequest.CookieContainer = cookieContainer;
webRequest.Method = "post";
Stream request = webRequest.GetRequestStream();
StreamWriter streamWriter = new StreamWriter(request, Encoding.GetEncoding("gb2312"));
streamWriter.Write(payload);
streamWriter.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
Stream returnStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(returnStream, Encoding.GetEncoding("utf-8"));
string endResult = streamReader.ReadToEnd();//返回結(jié)果
streamReader.Close();
returnStream.Close();
return endResult;
}
}
}
微信小程序 代碼示例:
wx.request({
url: 'http://openapiai.xueersi.com/v1/api/img/ocr/photo_search',
method: "post",
data:
{
app_key: "8102b22a5e81e840176d9f381ec6f837",
img: "https://ai.xueersi.com/textRecognition/images/22.jpg",
img_type: "URL",
},
header: {
"content-type": "application/x-www-form-urlencoded",
},
success(res) {
console.log(res.data)
}
})
iOS 代碼示例:
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlStr = @"http://openapiai.xueersi.com/v1/api/img/ocr/photo_search";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
NSString *app_key = @"app_key=8102b22a5e81e840176d9f381ec6f837";
NSString *img = @"img=https://ai.xueersi.com/textRecognition/images/22.jpg";
NSString *img_type = @"img_type=URL";
NSString *paramsStr = [NSString stringWithFormat:@"%@&%@&%@", app_key, img, img_type];
request.HTTPBody = [paramsStr dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"result=%@",dict);
}];
[dataTask resume];
安全接入方式
請(qǐng)求參數(shù)詳情
參數(shù)名
類型
是否必選
賦值說(shuō)明
樣例
備注
app_key
string
是
應(yīng)用標(biāo)識(shí)
8102b22a5e81e840176d9f381ec6f837
time_stamp
string
是
秒級(jí)時(shí)間戳
1493468759
安全接入必備,用于唯一地標(biāo)識(shí)某一刻的時(shí)間
nonce_str
string
是
隨機(jī)字符串
dd599ef889859f9fe
安全接入必備
sign
string
是
簽名信息
99880aabb33f4def5c875875b6bdc3b1
安全接入必備
img_type
string
是
圖像形式
URL
base64 / URL
subject_id
integer
否
學(xué)科id
1:語(yǔ)文,2:數(shù)學(xué),3:英語(yǔ),4:物理,5:化學(xué),6:生物,7:政治,8:歷史,9:地理,20:趣味,21:科學(xué),25:生化,26:編程,44:人文
默認(rèn)0
請(qǐng)求代碼示例
HTTP 代碼示例:
POST /v1/api/img/ocr/photo_search HTTP/1.1
Host: openapiai.xueersi.com
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a
cURL 代碼示例:
curl -X POST \
http://openapiai.xueersi.com/v1/api/img/ocr/photo_search \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a'
PHP 代碼示例:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Python(Python3) 代碼示例:
URL傳參方式:
import http.client
conn = http.client.HTTPConnection("openapiai.xueersi.com")
payload = "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
conn.request("POST", "/v1/api/img/ocr/photo_search/", payload, headers)
res = conn.getresponse()
data = res.read()
#python2.7
#print(data)
#python3.6
print(data.decode("utf-8"))
conn.close()
base64傳參方式:
import http.client
import urllib
import base64
from urllib import quote
with open('./test.jpg', 'rb') as bin_data:
image_data = bin_data.read()
image_data_base64 = base64.b64encode(image_data)
image_data_base64 = quote(image_data_base64)
conn = http.client.HTTPConnection("openapiai.xueersi.com")
appkey_string = 'app_key=8102b22a5e81e840176d9f381ec6f837'
img_string = 'img=' + image_data_base64
img_type_string = 'img_type=base64'
payload = appkey_string + '&' + img_string + '&' + img_type_string + '&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a'
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
conn.request("POST", "/v1/api/img/ocr/photo_search/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
conn.close()
C++(LibCurl) 代碼示例:
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "cache-control: no-cache");
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a");
CURLcode ret = curl_easy_perform(hnd);
Java 代碼示例:
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a");
Request request = new Request.Builder()
.url("http://openapiai.xueersi.com/v1/api/img/ocr/photo_search")
.post(body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
JavaScript 代碼示例:
var settings = {
"async": true,
"crossDomain": true,
"url": "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
},
"data": {
"app_key": "8102b22a5e81e840176d9f381ec6f837",
"img": "https://ai.xueersi.com/textRecognition/images/22.jpg",
"img_type": "URL",
"time_stamp": "1551174536",
"nonce_str": "W8FI8oCp",
"sign": "c08d8f9900479a3b2a348c1d7dc7e918e71be66a"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Go 代碼示例:
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search"
payload := strings.NewReader("app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
C# 代碼示例:
using System;
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string safetyPost = SafetyPost();
Console.WriteLine("安全接入方式:\n" + safetyPost);
Console.ReadLine();
}
private static string SafetyPost()
{
string url = "http://openapiai.xueersi.com/v1/api/img/ocr/photo_search";//URL地址
string payload = "app_key=8102b22a5e81e840176d9f381ec6f837&img=https%3A%2F%2Fai.xueersi.com%2FtextRecognition%2Fimages%2F22.jpg&img_type=URL&time_stamp=1551174536&nonce_str=W8FI8oCp&sign=7d15e530e58fcf3a020ec69b48d951010fa49322";
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentLength = Encoding.UTF8.GetByteCount(payload);
webRequest.ContentType = "application/x-www-form-urlencoded";//Content-Type
webRequest.CookieContainer = cookieContainer;
webRequest.Method = "post";
Stream request = webRequest.GetRequestStream();
StreamWriter streamWriter = new StreamWriter(request, Encoding.GetEncoding("gb2312"));
streamWriter.Write(payload);
streamWriter.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
Stream returnStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(returnStream, Encoding.GetEncoding("utf-8"));
string endResult = streamReader.ReadToEnd();//返回結(jié)果
streamReader.Close();
returnStream.Close();
return endResult;
}
}
}
微信小程序 代碼示例:
wx.request({
url: 'http://openapiai.xueersi.com/v1/api/img/ocr/photo_search',
method: "post",
data:
{
app_key: "8102b22a5e81e840176d9f381ec6f837",
img: "https://ai.xueersi.com/textRecognition/images/22.jpg",
img_type: "URL",
time_stamp: "1551174536",
nonce_str: "W8FI8oCp",
sign: "c08d8f9900479a3b2a348c1d7dc7e918e71be66a"
},
header: {
"content-type": "application/x-www-form-urlencoded",
},
success(res) {
console.log(res.data)
}
})
iOS 代碼示例:
NSURLSession *session = [NSURLSession sharedSession];
NSString *urlStr = @"http://openapiai.xueersi.com/v1/api/img/ocr/photo_search";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
NSString *app_key = @"app_key=8102b22a5e81e840176d9f381ec6f837";
NSString *img = @"img=https://ai.xueersi.com/textRecognition/images/22.jpg";
NSString *img_type = @"img_type=URL";
NSString *time_stamp = @"time_stamp=1551174536";
NSString *nonce_str = @"nonce_str=W8FI8oCp";
NSString *sign = @"sign=c08d8f9900479a3b2a348c1d7dc7e918e71be66a";
NSString *paramsStr = [NSString stringWithFormat:@"%@&%@&%@&%@&%@&%@", app_key, img, img_type, time_stamp, nonce_str, sign];
request.HTTPBody = [paramsStr dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"result=%@",dict);
}];
[dataTask resume];
返回響應(yīng)
返回格式
JSON格式
響應(yīng)參數(shù)說(shuō)明
參數(shù)名
類型
賦值說(shuō)明
樣例
備注
code
string
返回碼
0
msg
string
返回碼解釋
"請(qǐng)求成功"
data
object
識(shí)別數(shù)據(jù)結(jié)構(gòu)
數(shù)據(jù)結(jié)構(gòu)
id
string
試題id
試題id
parent_id
int
父級(jí)id,父級(jí)不為0則為改編類型試題
父級(jí)id,父級(jí)不為0則為改編類型試題
answer
string
試題原始答案,不做任何業(yè)務(wù)使用
試題原始答案,不做任何業(yè)務(wù)使用
answer2
string
試題答案2,此答案用于用戶作答驗(yàn)證使用,(填空題去除答案分隔符[|||]及l(fā)atex標(biāo)示符$$符后答案)
試題答案2,此答案用于用戶作答驗(yàn)證使用,(填空題去除答案分隔符[|||]及l(fā)atex標(biāo)示符$$符后答案)
answer3
string
試題答案3,此答案用戶頁(yè)面渲染展示使用(此答案去除答案分隔符[|||],保留latex標(biāo)示符$$)
stem
string
試題題干
type
string
試題類別(1 填空 2選擇 3解答 4語(yǔ)音測(cè)評(píng))
analytic
string
試題解析
"試題解析內(nèi)容"
categoryId
string
試題題型id
choice_type
int
選擇題類型 1單選題 2多選題
material_id
string
試題材料id
material_audio
string
試題材料音頻
is_objective
string
是否為客觀題 1 是 2否
material_content
string
材料內(nèi)容
audio.content
string array
試題音頻鏈接結(jié)合,如果不存在,則為空數(shù)組
audio.stem
string array
試題題干音頻文件
audio.analytic
string array
題解析音頻文件
serial_num
string
試題在材料題下序號(hào)
option
object array
試題選項(xiàng),選擇題使用此字段,其他類型試題不使用此字段
knowledge
object
試題知識(shí)點(diǎn)信息
option_num
int
選擇題為正確答案?jìng)€(gè)數(shù),填空題為空個(gè)數(shù)
programming_url
object
編程試題url,只有試題題型為3解答題的時(shí)候才存在此字段信息
programming_url.stem
string array
programming_url.analytic
string array
響應(yīng)代碼示例
響應(yīng)Body:
{
"code": 0,
"msg": "請(qǐng)求成功",
"data": {
"data": {
"list": [{
"analytic": "解:根據(jù)題意,三角形的兩角和它們的夾邊是完整的,所以可以利用“角邊角”定理作出完全一樣的三角形.\u003cbr\u003e\n故選D.",
"answer": "D",
"answer2": ["D"],
"answer3": ["D"],
"audio": [],
"categoryId": "51",
"choice_type": "1",
"department": "2",
"display_type": "0",
"id": "113892",
"is_objective": "1",
"knowledge": {
"7961": {
"alias_name": "",
"id": "7961",
"name": "ASA"
}
},
"material_audio": [],
"material_content": "",
"material_id": 0,
"material_topic_answer": [],
"option": [{
"content": "$$\\text{SSS}$$",
"is_right": "0",
"label": "A"
}, {
"content": "$$\\text{SAS}$$",
"is_right": "0",
"label": "B"
}, {
"content": "$$\\text{AAS}$$",
"is_right": "0",
"label": "C"
}, {
"content": "$$\\text{ASA}$$",
"is_right": "1",
"label": "D"
}],
"option_num": 4,
"parent_id": 0,
"programming_url": [],
"serial_num": 0,
"stem": "如圖所示,亮亮?xí)系娜切伪荒E污染了一部分,很快他就根據(jù)所學(xué)知識(shí)畫出一個(gè)與書上完全一樣的三角形,那么這兩個(gè)三角形完全一樣的依據(jù)是( )\u003cbr\u003e\n\u003cimg src=\"https://hw.xesimg.com/test_library/img/2018/10/17/t_113892_54_104x93.png?1539772112\"\u003e",
"subject_id": "2",
"type": "2"
}, {
"analytic": "解:根據(jù)題意,三角形的兩角和它們的夾邊是完整的,所以可以利用“角邊角”定理作出完全一樣的三角形.\u003cbr\u003e\n故選A. \u003cbr\u003e\n考點(diǎn):全等三角形的應(yīng)用\n\n",
"answer": "A",
"answer2": ["A"],
"answer3": ["A"],
"audio": [],
"categoryId": "51",
"choice_type": "1",
"department": "2",
"display_type": "0",
"id": "447944",
"is_objective": "1",
"knowledge": {
"7961": {
"alias_name": "",
"id": "7961",
"name": "ASA"
}
},
"material_audio": [],
"material_content": "",
"material_id": 0,
"material_topic_answer": [],
"option": [{
"content": "$$ASA$$ ",
"is_right": "1",
"label": "A"
}, {
"content": "$$SAS $$ ",
"is_right": "0",
"label": "B"
}, {
"content": "$$AAS$$",
"is_right": "0",
"label": "C"
}, {
"content": "$$SSS $$ ",
"is_right": "0",
"label": "D"
}],
"option_num": 4,
"parent_id": 0,
"programming_url": [],
"serial_num": 0,
"stem": "如圖所示,小明試卷上的三角形被墨跡污染了一部分,很快他就根據(jù)所學(xué)知識(shí)畫出一個(gè)與試卷原圖完全一樣的三角形,那么兩個(gè)三角形完全一樣的依據(jù)是( ) \u003cbr\u003e\n\u003cimg src=\"https://mr.xesimg.com/test_library/ordinaryimg/2016/05/14/t_447944_7_205x81.png\"\u003e",
"subject_id": "2",
"type": "2"
}, {
"analytic": "根據(jù)題意,三角形的兩個(gè)角和它們的夾邊是完整的,所以可以利用"角邊角"定理作出完全一樣的三角形. \u003cbr\u003e\n故選:C. \u003cbr\u003e\n考點(diǎn):全等三角形的應(yīng)用. ",
"answer": "C",
"answer2": ["C"],
"answer3": ["C"],
"audio": [],
"categoryId": "51",
"choice_type": "1",
"department": "2",
"display_type": "0",
"id": "446440",
"is_objective": "1",
"knowledge": {
"7961": {
"alias_name": "",
"id": "7961",
"name": "ASA"
}
},
"material_audio": [],
"material_content": "",
"material_id": 0,
"material_topic_answer": [],
"option": [{
"content": "$$SSS$$ ",
"is_right": "0",
"label": "A"
}, {
"content": "$$SAS$$ ",
"is_right": "0",
"label": "B"
}, {
"content": "$$ASA$$ ",
"is_right": "1",
"label": "C"
}, {
"content": "$$AAS$$ ",
"is_right": "0",
"label": "D"
}],
"option_num": 4,
"parent_id": 0,
"programming_url": [],
"serial_num": 0,
"stem": "如圖,聰聰書上的三角形被墨跡污染了一部分,他根據(jù)所學(xué)知識(shí)很快就畫了一個(gè)與書本上完全一樣的三角形,那么聰聰畫圖的依據(jù)是( ) \u003cbr\u003e\n\u003cimg src=\"https://hw.xesimg.com/test_library/img/2017/12/09/t_446440_6-1_157x126.png?1512806402\"\u003e",
"subject_id": "2",
"type": "2"
}, {
"analytic": "解:小明書上的三角形被墨水污染了,他根據(jù)所學(xué)知識(shí)畫出了完全一樣的一個(gè)三角形,\u003cbr\u003e\n他根據(jù)的定理是:兩角及其夾邊分別相等的兩個(gè)三角形全等$$\\left( \\text{ASA} \\right)$$.\u003cbr\u003e\n故答案為:D.\u003cbr\u003e",
"answer": "D",
"answer2": ["D"],
"answer3": ["D"],
"audio": [],
"categoryId": "51",
"choice_type": "1",
"department": "2",
"display_type": "0",
"id": "1139943",
"is_objective": "1",
"knowledge": {
"7961": {
"alias_name": "",
"id": "7961",
"name": "ASA"
}
},
"material_audio": [],
"material_content": "",
"material_id": 0,
"material_topic_answer": [],
"option": [{
"content": "$$\\text{SSS}$$",
"is_right": "0",
"label": "A"
}, {
"content": "$$\\text{SAS}$$",
"is_right": "0",
"label": "B"
}, {
"content": "$$\\text{AAS}$$",
"is_right": "0",
"label": "C"
}, {
"content": "$$\\text{ASA}$$",
"is_right": "1",
"label": "D"
}],
"option_num": 4,
"parent_id": 0,
"programming_url": [],
"serial_num": 0,
"stem": "如圖所示,小明書上的三角形被墨水污染了,他根據(jù)所學(xué)知識(shí)畫出了完全一樣的一個(gè)三角形,他根據(jù)的定理是( )\u003cbr\u003e\n\u003cimg src=\"https://mr.xesimg.com/test_library/img/2018/08/03/t_1139943_2_302x220.png?1533275497\"\u003e",
"subject_id": "2",
"type": "2"
}, {
"analytic": "解:根據(jù)題意,三角形的兩角和它們的夾邊是完整的,所以可以利用“角邊角”定理作出完全一樣的三角形.\u003cbr\u003e\n故答案為:兩角和它們的夾邊分別相等的兩個(gè)三角形全等.",
"answer": "[|||]兩角和它們的夾邊分別相等的兩個(gè)三角形全等[|||]",
"answer2": ["兩角和它們的夾邊分別相等的兩個(gè)三角形全等"],
"answer3": ["兩角和它們的夾邊分別相等的兩個(gè)三角形全等"],
"answer4": [
["兩角和它們的夾邊分別相等的兩個(gè)三角形全等"]
],
"audio": [],
"categoryId": "52",
"choice_type": 0,
"department": "2",
"display_type": "0",
"id": "1040364",
"is_objective": "0",
"knowledge": {
"7957": {
"alias_name": "",
"id": "7957",
"name": "全等形的性質(zhì)"
},
"7961": {
"alias_name": "",
"id": "7961",
"name": "ASA"
}
},
"material_audio": [],
"material_content": "",
"material_id": 0,
"material_topic_answer": [],
"option": {
"1": {
"content": "兩角和它們的夾邊分別相等的兩個(gè)三角形全等"
}
},
"option_num": 1,
"parent_id": 0,
"programming_url": [],
"serial_num": 0,
"stem": "如圖所示,亮亮?xí)系娜切伪荒E污染了一部分,他根據(jù)所學(xué)的知識(shí)很快就畫出了一個(gè)與書上完全一樣的三角形,那么亮亮畫圖的依據(jù)是\u003cspan class='test_blank' style='width:192px'\u003e\u0026nbsp;\u003c/span\u003e.\u003cbr\u003e\n\u003cimg src=\"https://hw.xesimg.com/test_library/img/2018/08/03/t_1040364_bjsb4_189x119.png?1533290915\"\u003e",
"subject_id": "2",
"type": "1"
}],
"rows": 210494
},
"status": 100
}
}
常見問題及反饋
總結(jié)
以上是生活随笔為你收集整理的python拍照搜题_OCR拍照搜题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用ElasticSearch存储日志
- 下一篇: IOS(常用移动终端设备) push实现