Files
2024-09-27 01:32:49 +08:00

304 lines
10 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipImageClassify extends AipBase {
/**
* 通用物体识别 advanced_general api url
* @var string
*/
private $advancedGeneralUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general';
/**
* 菜品识别 dish_detect api url
* @var string
*/
private $dishDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/dish';
/**
* 车辆识别 car_detect api url
* @var string
*/
private $carDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car';
/**
* logo商标识别 logo_search api url
* @var string
*/
private $logoSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/logo';
/**
* logo商标识别—添加 logo_add api url
* @var string
*/
private $logoAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add';
/**
* logo商标识别—删除 logo_delete api url
* @var string
*/
private $logoDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete';
/**
* 动物识别 animal_detect api url
* @var string
*/
private $animalDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/animal';
/**
* 植物识别 plant_detect api url
* @var string
*/
private $plantDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/plant';
/**
* 图像主体检测 object_detect api url
* @var string
*/
private $objectDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect';
/**
* 地标识别 landmark api url
* @var string
*/
private $landmarkUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark';
/**
* 通用物体识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function advancedGeneral($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->advancedGeneralUrl, $data);
}
/**
* 菜品识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为5
* filter_threshold 默认0.95,可以通过该参数调节识别效果,降低非菜识别率.
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function dishDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->dishDetectUrl, $data);
}
/**
* 车辆识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为5
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function carDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->carDetectUrl, $data);
}
/**
* logo商标识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* custom_lib 是否只使用自定义logo库的结果默认false返回自定义库+默认库的识别结果
* @return array
*/
public function logoSearch($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->logoSearchUrl, $data);
}
/**
* logo商标识别—添加接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param string $brief - brief检索时带回。此处要传对应的name与code字段name长度小于100Bcode长度小于150B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoAdd($image, $brief, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data['brief'] = $brief;
$data = array_merge($data, $options);
return $this->request($this->logoAddUrl, $data);
}
/**
* logo商标识别—删除接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoDeleteByImage($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->logoDeleteUrl, $data);
}
/**
* logo商标识别—删除接口
*
* @param string $contSign - 图片签名和image二选一image优先级更高
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoDeleteBySign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->logoDeleteUrl, $data);
}
/**
* 动物识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为6
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function animalDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->animalDetectUrl, $data);
}
/**
* 植物识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function plantDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->plantDetectUrl, $data);
}
/**
* 图像主体检测接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* with_face 如果检测主体是人主体区域是否带上人脸部分0-不带人脸区域,其他-带人脸区域,裁剪类需求推荐带人脸,检索/识别类需求推荐不带人脸。默认取1带人脸。
* @return array
*/
public function objectDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->objectDetectUrl, $data);
}
/**
* 地标识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function landmark($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->landmarkUrl, $data);
}
}