加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 学习资料

图像识别API调用代码实例(PHP)

时间:2021-03-21 23:49:30  来源:  作者:
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
1.添加商品信息
2.添加图片
3.查询所有产品
4.查询某个具体产品信息
5.删除某个产品
6.删除图片
7.图像识别

图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey

PHP示例:
  1. <!--?php
  2. // +----------------------------------------------------------------------
  3. // | JuhePHP [ NO ZUO NO DIE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: Juhedata <info@juhe.cn-->
  8. // +----------------------------------------------------------------------
  9.  
  10. //----------------------------------
  11. // 图像识别调用示例代码 - 聚合数据
  12. // 在线接口文档:http://www.juhe.cn/docs/117
  13. //----------------------------------
  14.  
  15. header('Content-type:text/html;charset=utf-8');
  16.  
  17.  
  18. //配置您申请的appkey
  19. $appkey = "*********************";
  20.  
  21.  
  22.  
  23.  
  24. //************1.图像上传************
  25. $url = "http://japi.juhe.cn/image_recognition/upload";
  26. $params = array(
  27.       "file" => "",//上传的单张图片
  28.       "key" => $appkey,//APP Key
  29.       "pname" => "",//包名
  30. );
  31. $paramstring = http_build_query($params);
  32. $content = juhecurl($url,$paramstring,1);
  33. $result = json_decode($content,true);
  34. if($result){
  35.     if($result['error_code']=='0'){
  36.         print_r($result);
  37.     }else{
  38.         echo $result['error_code'].":".$result['reason'];
  39.     }
  40. }else{
  41.     echo "请求失败";
  42. }
  43. //**************************************************
  44.  
  45.  
  46.  
  47.  
  48. //************2.查寻上传图像信息************
  49. $url = "http://japi.juhe.cn/image_recognition/findAll";
  50. $params = array(
  51.       "key" => $appkey,//APP Key
  52. );
  53. $paramstring = http_build_query($params);
  54. $content = juhecurl($url,$paramstring);
  55. $result = json_decode($content,true);
  56. if($result){
  57.     if($result['error_code']=='0'){
  58.         print_r($result);
  59.     }else{
  60.         echo $result['error_code'].":".$result['reason'];
  61.     }
  62. }else{
  63.     echo "请求失败";
  64. }
  65. //**************************************************
  66.  
  67.  
  68.  
  69.  
  70. //************3.删除图像信息************
  71. $url = "http://japi.juhe.cn/image_recognition/delete";
  72. $params = array(
  73.       "key" => $appkey,//APP Key
  74.       "imageId" => "",//图片ID
  75. );
  76. $paramstring = http_build_query($params);
  77. $content = juhecurl($url,$paramstring);
  78. $result = json_decode($content,true);
  79. if($result){
  80.     if($result['error_code']=='0'){
  81.         print_r($result);
  82.     }else{
  83.         echo $result['error_code'].":".$result['reason'];
  84.     }
  85. }else{
  86.     echo "请求失败";
  87. }
  88. //**************************************************
  89.  
  90.  
  91.  
  92.  
  93. //************4.图像识别************
  94. $url = "http://japi.juhe.cn/image_recognition/check";
  95. $params = array(
  96.       "file" => "",//上传的图片
  97.       "key" => $appkey,//APP Key
  98.       "pname" => "",//包名
  99.       "device_name" => "",//设备名称(如android OS或iphone OS)
  100.       "device_version" => "",//设备版本(如:4.0.3)
  101.       "latitude" => "",//纬度
  102.       "longitude" => "",//经度
  103.       "uuid" => "",//设备id
  104.       "zone" => "",//请求地区
  105. );
  106. $paramstring = http_build_query($params);
  107. $content = juhecurl($url,$paramstring,1);
  108. $result = json_decode($content,true);
  109. if($result){
  110.     if($result['error_code']=='0'){
  111.         print_r($result);
  112.     }else{
  113.         echo $result['error_code'].":".$result['reason'];
  114.     }
  115. }else{
  116.     echo "请求失败";
  117. }
  118. //**************************************************
  119.  
  120.  
  121.  
  122.  
  123.  
  124. /**
  125. * 请求接口返回内容
  126. * @param  string $url [请求的URL地址]
  127. * @param  string $params [请求的参数]
  128. * @param  int $ipost [是否采用POST形式]
  129. * @return  string
  130. */
  131. function juhecurl($url,$params=false,$ispost=0){
  132.     $httpInfo = array();
  133.     $ch = curl_init();
  134.  
  135.     curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  136.     curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
  137.     curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
  138.     curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
  139.     curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  140.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  141.     if( $ispost )
  142.     {
  143.         curl_setopt( $ch , CURLOPT_POST , true );
  144.         curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  145.         curl_setopt( $ch , CURLOPT_URL , $url );
  146.     }
  147.     else
  148.     {
  149.         if($params){
  150.             curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  151.         }else{
  152.             curl_setopt( $ch , CURLOPT_URL , $url);
  153.         }
  154.     }
  155.     $response = curl_exec( $ch );
  156.     if ($response === FALSE) {
  157.         //echo "cURL Error: " . curl_error($ch);
  158.         return false;
  159.     }
  160.     $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  161.     $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  162.     curl_close( $ch );
  163.     return $response;
  164. }
复制代码

 
 
 
 
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
实现php间隔一段时间执行一次某段代码
实现php间隔一段时间
相关文章
    无相关信息
栏目更新
栏目热门