根据图片识别动物
请求Header:
| 名称 | 值 | |
|---|---|---|
| Content-Type | application/x-www-form-urlencoded |
请求参数说明:
| 名称 | 必填 | 类型 | 说明 | |
|---|---|---|---|---|
| image | 是 | string | 动物图片,base64编码,编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式 。注意:图片需要base64编码、去掉编码头后再进行urlencode。 | |
| key | 是 | string | 在个人中心->我的数据,接口名称上方查看 |
请求代码示例:
curl -k -i -d "key=key&image=xxx" "https://apis.juhe.cn/animalDetect/index"
<?php
/**
* 1259-根据图片识别动物 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/animalDetect/index"; // 接口请求URL
$method = "POST"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'image'=> '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
# 1259-根据图片识别动物 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/animalDetect/index' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'image': '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/animalDetect/index"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("image", "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/animalDetect/index";
string apiKey = "您申请的调用APIkey";
using (WebClient client = new WebClient())
{
var data = new NameValueCollection();
// 添加元素到 NameValueCollection
data.Add("key", apiKey);
data.Add( "image", "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/animalDetect/index'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
image: '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/animalDetect/index";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("image", "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/animalDetect/index"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"image": @"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 | int | 返回码 | |
| reason | string | 返回说明 | |
| result | string | 返回结果集 | |
| name | string | 动物名称,示例:非洲象 | |
| score | string | 置信度,如0.9984 | |
| baike_url | string | 百科词条名称,可能为空 | |
| image_url | string | 百科图片链接,可能为空 | |
| description | string | 百科内容描述,可能为空 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "success",
"result": {
"data": [
{
"score": "0.978753",
"name": "非洲象",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E9%9D%9E%E6%B4%B2%E8%B1%A1%E5%B1%9E/19728828",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/574e9258d109b3de1df1cc5cc4bf6c81800a4cb3.jpg",
"description": "非洲象属(学名:Loxodonta):是象科的一个属,于1825年由乔治·库维叶男爵(Baron Georges Cuvier)命名。成年非洲雄象高于3.5米,最高更可达4.1米。体重约为4至5吨,最重记录有10吨。它们的长牙最高记录有102.7千克重。该属包括二个物种,非洲草原象,非洲森林象,分6个亚种。非洲象是陆地上最大的哺乳动物,雄性和雌性呈二态性(雌雄两性在体形或身体特征上都有所不同)。该属的两种象均产于非洲,它们可以生活于从海平面到海拔5000米的多种自然环境中,包括森林、开阔草原、草地、刺丛以及半干旱的丛林。因为象牙,无数的非洲大象就被杀害。非洲象被美国濒危物种法案和《世界自然保护联盟》列为濒危物种,被《华盛顿公约》CITES列入附录I,但是在津巴布韦、博茨瓦纳和纳米比亚三国,非洲象被重新划定到CITES附录II。其中非洲草原象是科特迪瓦,莫桑比克的国兽。"
}
},
{
"score": "0.0178928",
"name": "亚洲象",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E4%BA%9A%E6%B4%B2%E8%B1%A1/518517",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/7dd98d1001e93901f0f01c6b7cec54e737d196f1.jpg",
"description": "亚洲象(拉丁学名:Elephas maximus Linnaeus ),别名印度象、大象、亚洲大象,属于长鼻目、象科。亚洲象是亚洲现存的最大陆生动物,长达1米多的象牙,是雄象上颌突出口外的门齿,也是强有力的防卫武器。象的眼小耳大,耳朵向后可遮盖颈部两侧。四肢粗大强壮,前肢5趾,后肢4趾。尾短而细,皮厚多褶皱,全身被稀疏短毛。头顶为最高点,体长5~6米,身高2.1~3.6米,体重达3~5吨。野生象现已很少,在东南亚一些国家驯养的家象、役象很多。中国的野生象仅分布于云南省南部与缅甸、老挝相邻的边境地区,数量十分稀少,屡遭猎杀,破坏十分严重。属于国家一级保护动物。(概述图来源:)"
}
},
{
"score": "0.000752572",
"name": "野象",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E9%87%8E%E8%B1%A1/732047",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/3b292df5e0fe99253c3453fc3ea85edf8db17165.jpg",
"description": "野象,哺乳纲1目,通称象,是生活在陆地上最大的哺乳动物,主要外部特征为柔韧而肌肉发达的长鼻,具缠卷的功能,是象自卫和取食的有力工具。本目仅有象科1科共2属2种,即亚洲象,非洲象。亚洲象历史上曾广布于中国长江以南的南亚和东南亚地区,现分布范围已缩小,主要产于印度、泰国、柬埔寨、越南等国。中国云南省西双版纳地区也有小的野生种群。非洲象则广泛分布于整个非洲大陆。"
}
},
{
"score": "0.000160566",
"name": "猛犸象",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E7%8C%9B%E7%8A%B8%E8%B1%A1/770285",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/11385343fbf2b21165d8d3c5c18065380dd78e43.jpg",
"description": "猛犸象(Mammuthus primigenius),又名毛象(长毛象),是一种适应寒冷气候的动物。曾经是世界上最大的象之一,在陆地上生存过的最大的哺乳动物之一,其中草原猛犸象体重可达12吨。它是冰川世纪的一个庞然大物。猛犸象身高体壮,有粗壮的腿,脚生四趾,头大。其中,母象的象牙普遍在1米5至2米。而公的猛犸象象牙平均长达2米2至2米5。个别的可以接近甚至超过3米。它身上披着金、红棕、灰褐色的细密长毛,皮很厚,具有极厚的脂肪层,厚度最厚可达9厘米。它们广泛生活在欧亚大陆北部。公元前1万年猛犸象陆续灭绝,这被视作一个冰川时代结束的标志。在阿拉斯加,西伯利亚的冻土和冰层里,不止一次发现冷冻的尸体。 当地时间2016年5月17日,墨西哥国家人类学和历史研究所的考古学家挖掘大量猛犸象牙化石。据了解,猛犸象牙化石在2015年12月被发现,年代为更新世时期。"
}
},
{
"score": "4.14813e-05",
"name": "海象",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E6%B5%B7%E8%B1%A1/793764",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/d1160924ab18972bc732fe08e4cd7b899f510ae3.jpg",
"description": "海象学名:Odobenus rosmarus(Linnaeus,1758),海象科海象属的一种动物。顾名思义,即海中的大象,它身体庞大,皮厚而多皱,有稀疏的刚毛,眼小,视力欠佳。长着两枚长长的牙。与陆地上肥头大耳、长长的鼻子、四肢粗壮的大象不同的是,它的四肢因适应水中生活已退化成鳍状,不能像大象那样步行于陆上,仅靠后鳍脚朝前弯曲,以及獠牙刺入冰中的共同作用,才能在冰上匍匐前进,所以海象的学名,若用中文直译便是用牙一起步行者,而且其鼻子短短的,缺乏耳壳,看起来十分丑陋。"
}
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
| 错误码 | 说明 | |
|---|---|---|
| 237301 | 识别失败 | |
| 237302 | 非动物或识别不到信息 |
系统级错误码参照:
| 错误码 | 说明 | 旧版本(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号