根据图片识别植物
请求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/plantDetect/index"
<?php
/**
* 1261-根据图片识别植物 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/plantDetect/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
# 1261-根据图片识别植物 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/plantDetect/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/plantDetect/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/plantDetect/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/plantDetect/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/plantDetect/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/plantDetect/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 | number | 置信度,如0.9984 | |
| baike_url | string | 百科词条名称,可能为空 | |
| image_url | string | 百科图片链接,可能为空 | |
| description | string | 百科内容描述,可能为空 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "success",
"result": {
"data": [
{
"score": 0.63999998569489,
"name": "水仙",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E6%B0%B4%E4%BB%99/6410",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/b2de9c82d158ccbf9bee30df1bd8bc3eb0354181.jpg",
"description": "水仙(Narcissus tazetta L.var.chinensis Roem.):又名中国水仙,是多花水仙的一个变种。是石蒜科多年生草本植物。水仙的叶由鳞茎顶端绿白色筒状鞘中抽出花茎(俗称箭)再由叶片中抽出。一般每个鳞茎可抽花茎1-2枝,多者可达8-11枝,伞状花序。花瓣多为6片,花瓣末处呈鹅黄色。花蕊外面有一个如碗一般的保护罩。鳞茎卵状至广卵状球形,外被棕褐色皮膜。叶狭长带状,蒴果室背开裂。花期春季。水仙性喜温暖、湿润、排水良好。在中国已有一千多年栽培历史,为传统观赏花卉,是中国十大名花之十。水仙鳞茎多液汁,有毒,含有石蒜碱、多花水仙碱等多种生物碱;外科用作镇痛剂;鳞茎捣烂敷治痈肿。牛羊误食鳞茎,立即出现痉挛、瞳孔放大、暴泻等。(概述图片参考资料来源:)"
}
},
{
"score": 0.35957098007202,
"name": "半钟铁线莲",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E5%8D%8A%E9%92%9F%E9%93%81%E7%BA%BF%E8%8E%B2/9265482",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/728da9773912b31b5466e5328e18367adab4e1a7.jpg",
"description": "半钟铁线莲(学名:Clematis ochotensis (Pall.) Poir.)是毛茛科,铁线莲属多年生木质藤本植物。茎圆柱形,光滑无毛,当年生枝基部及叶腋有宿存的芽鳞,鳞片披针形,顶端有尖头,表面密被白色柔毛,小叶片窄卵状披针形至卵状椭圆形,顶端钝尖,上部边缘有粗牙齿,小叶柄短;花单生于当年生枝顶,钟状,萼片淡蓝色,长方椭圆形至狭倒卵形,化雄蕊成匙状条形,顶端圆形,雄蕊短于退化雄蕊,花丝线形而中部较宽,边缘被毛,花药内向着生;瘦果倒卵形,棕红色,5月至6月开花,7月至8月结果。分布于中国山西北部、河北北部、吉林东部及黑龙江省。日本、俄罗斯远东地区也有分布生于海拔600-1200米的山谷、林边及灌丛中。(概述图参考来源:中国自然标本馆)"
}
},
{
"score": 0.046597998589277,
"name": "黄水仙",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E9%BB%84%E6%B0%B4%E4%BB%99/2221403",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/4034970a304e251f23122e24a586c9177e3e5301.jpg",
"description": "黄水仙(学名:Narcissus pseudonarcissus L.):为多年生草本,有皮鳞茎卵圆形,花横向或略向上开放,外花冠成喇叭形、黄色,边缘呈不规则齿状皱榴。黄水仙花茎挺拔,花朵硕大,副花冠多变,花色温柔和谐,清香诱人,是世界著名的球根花卉。自19世纪起,英国的黄水仙大量减少,这是由于农业耕地增加、森林砍伐以及园艺用鳞茎的大量挖掘。黄水仙原产法国、西班牙、葡萄牙。喜温暖、湿润和阳光充足环境。黄水仙在不同生长发育阶段对温度的要求不同。黄水仙对温度的适应性比较强。"
}
},
{
"score": 0.012638071551919,
"name": "天蒜",
"baike_info": {
"baike_url": "http://baike.baidu.com/item/%E5%A4%A9%E9%9F%AD/4937169",
"image_url": "http://imgsrc.baidu.com/baike/pic/item/5ab5c9ea15ce36d3f87e940d30f33a87e950b190.jpg",
"description": "天韭,中药名。为百合科葱属植物玉簪叶韭Allium funckiaefolium Hand.Mzt.的全草。植物玉簪叶韭,分布于陕西、湖北、四川等地。具有散瘀止痛,止血,解毒之功效。主治外疮肿痛,衄血,漆疮。"
}
},
{
"score": 0.010926142334938,
"name": "玉玲珑水仙",
"baike_info": {
"baike_url": "",
"image_url": "",
"description": ""
}
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
| 错误码 | 说明 | |
|---|---|---|
| 237401 | 识别失败 | |
| 237402 | 非植物或识别不到信息 |
系统级错误码参照:
| 错误码 | 说明 | 旧版本(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号