AipImageClassify - 副本.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /*
  3. * Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6. * use this file except in compliance with the License. You may obtain a copy of
  7. * the License at
  8. *
  9. * Http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. require_once 'lib/AipBase.php';
  18. class AipImageClassify extends AipBase {
  19. /**
  20. * 菜品识别 dish_detect api url
  21. * @var string
  22. */
  23. private $dishDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/dish';
  24. /**
  25. * 车辆识别 car_detect api url
  26. * @var string
  27. */
  28. private $carDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car';
  29. /**
  30. * logo商标识别 logo_search api url
  31. * @var string
  32. */
  33. private $logoSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/logo';
  34. /**
  35. * logo商标识别—添加 logo_add api url
  36. * @var string
  37. */
  38. private $logoAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add';
  39. /**
  40. * logo商标识别—删除 logo_delete api url
  41. * @var string
  42. */
  43. private $logoDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete';
  44. /**
  45. * 动物识别 animal_detect api url
  46. * @var string
  47. */
  48. private $animalDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/animal';
  49. /**
  50. * 植物识别 plant_detect api url
  51. * @var string
  52. */
  53. private $plantDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/plant';
  54. /**
  55. * 图像主体检测 object_detect api url
  56. * @var string
  57. */
  58. private $objectDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect';
  59. /**
  60. * 菜品识别接口
  61. *
  62. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  63. * @param array $options - 可选参数对象,key: value都为string类型
  64. * @description options列表:
  65. * top_num 返回预测得分top结果数,默认为5
  66. * @return array
  67. */
  68. public function dishDetect($image, $options=array()){
  69. $data = array();
  70. $data['image'] = base64_encode($image);
  71. $data = array_merge($data, $options);
  72. return $this->request($this->dishDetectUrl, $data);
  73. }
  74. /**
  75. * 车辆识别接口
  76. *
  77. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  78. * @param array $options - 可选参数对象,key: value都为string类型
  79. * @description options列表:
  80. * top_num 返回预测得分top结果数,默认为5
  81. * @return array
  82. */
  83. public function carDetect($image, $options=array()){
  84. $data = array();
  85. $data['image'] = base64_encode($image);
  86. $data = array_merge($data, $options);
  87. return $this->request($this->carDetectUrl, $data);
  88. }
  89. /**
  90. * logo商标识别接口
  91. *
  92. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  93. * @param array $options - 可选参数对象,key: value都为string类型
  94. * @description options列表:
  95. * custom_lib 是否只使用自定义logo库的结果,默认false:返回自定义库+默认库的识别结果
  96. * @return array
  97. */
  98. public function logoSearch($image, $options=array()){
  99. $data = array();
  100. $data['image'] = base64_encode($image);
  101. $data = array_merge($data, $options);
  102. return $this->request($this->logoSearchUrl, $data);
  103. }
  104. /**
  105. * logo商标识别—添加接口
  106. *
  107. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  108. * @param string $brief - brief,检索时带回。此处要传对应的name与code字段,name长度小于100B,code长度小于150B
  109. * @param array $options - 可选参数对象,key: value都为string类型
  110. * @description options列表:
  111. * @return array
  112. */
  113. public function logoAdd($image, $brief, $options=array()){
  114. $data = array();
  115. $data['image'] = base64_encode($image);
  116. $data['brief'] = $brief;
  117. $data = array_merge($data, $options);
  118. return $this->request($this->logoAddUrl, $data);
  119. }
  120. /**
  121. * logo商标识别—删除接口
  122. *
  123. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  124. * @param array $options - 可选参数对象,key: value都为string类型
  125. * @description options列表:
  126. * @return array
  127. */
  128. public function logoDeleteByImage($image, $options=array()){
  129. $data = array();
  130. $data['image'] = base64_encode($image);
  131. $data = array_merge($data, $options);
  132. return $this->request($this->logoDeleteUrl, $data);
  133. }
  134. /**
  135. * logo商标识别—删除接口
  136. *
  137. * @param string $contSign - 图片签名(和image二选一,image优先级更高)
  138. * @param array $options - 可选参数对象,key: value都为string类型
  139. * @description options列表:
  140. * @return array
  141. */
  142. public function logoDeleteBySign($contSign, $options=array()){
  143. $data = array();
  144. $data['cont_sign'] = $contSign;
  145. $data = array_merge($data, $options);
  146. return $this->request($this->logoDeleteUrl, $data);
  147. }
  148. /**
  149. * 动物识别接口
  150. *
  151. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  152. * @param array $options - 可选参数对象,key: value都为string类型
  153. * @description options列表:
  154. * top_num 返回预测得分top结果数,默认为6
  155. * @return array
  156. */
  157. public function animalDetect($image, $options=array()){
  158. $data = array();
  159. $data['image'] = base64_encode($image);
  160. $data = array_merge($data, $options);
  161. return $this->request($this->animalDetectUrl, $data);
  162. }
  163. /**
  164. * 植物识别接口
  165. *
  166. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  167. * @param array $options - 可选参数对象,key: value都为string类型
  168. * @description options列表:
  169. * @return array
  170. */
  171. public function plantDetect($image, $options=array()){
  172. $data = array();
  173. $data['image'] = base64_encode($image);
  174. $data = array_merge($data, $options);
  175. return $this->request($this->plantDetectUrl, $data);
  176. }
  177. /**
  178. * 图像主体检测接口
  179. *
  180. * @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
  181. * @param array $options - 可选参数对象,key: value都为string类型
  182. * @description options列表:
  183. * with_face 如果检测主体是人,主体区域是否带上人脸部分,0-不带人脸区域,其他-带人脸区域,裁剪类需求推荐带人脸,检索/识别类需求推荐不带人脸。默认取1,带人脸。
  184. * @return array
  185. */
  186. public function objectDetect($image, $options=array()){
  187. $data = array();
  188. $data['image'] = base64_encode($image);
  189. $data = array_merge($data, $options);
  190. return $this->request($this->objectDetectUrl, $data);
  191. }
  192. }