百度车牌识别demo
1 function get_token(){ 2 $url = 'https://aip.baidubce.com/oauth/2.0/token'; 3 $post_data['grant_type'] = 'client_credentials'; 4 $post_data['client_id'] = 'your key'; 5 $post_data['client_secret'] = 'your secret'; 6 $o = ""; 7 foreach ( $post_data as $k => $v ) 8 { 9 $o.= "$k=" . urlencode( $v ). "&" ; 10 } 11 $post_data = substr($o,0,-1); 12 $res = request_post($url, $post_data); 13 return $res["access_token"]; 14 //print_r($res); 15 //$access_token=$res["access_token"]; 16 } 17 18 /** 19 * 发起http post请求(REST API), 并获取REST请求的结果 20 * @param string $url 21 * @param string $param 22 * @return - http response body if succeeds, else false. 23 */ 24 function request_post($url = '', $param = ''){ 25 if (empty($url) || empty($param)) { 26 return false; 27 } 28 $postUrl = $url; 29 $curlPost = $param; 30 // 初始化curl 31 $curl = curl_init(); 32 curl_setopt($curl, CURLOPT_URL, $postUrl); 33 curl_setopt($curl, CURLOPT_HEADER, 0); 34 // 要求结果为字符串且输出到屏幕上 35 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 36 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 37 // post提交方式 38 curl_setopt($curl, CURLOPT_POST, 1); 39 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); 40 // 运行curl 41 $data = curl_exec($curl); 42 curl_close($curl); 43 return $data; 44 } 45 46 function get_chepai($img_path,$tk){ 47 $url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token=' . $tk; 48 $img = file_get_contents($img_path); 49 $img = base64_encode($img); 50 $bodys = array( 51 'image' => $img 52 ); 53 $res = request_post($url, $bodys) ; 54 return $res; 55 } 56 57 58 59 $img_path='./chepai/6.jpg'; 60 $tk=get_token(); 61 62 63 $res=get_chepai($img_path,$tk); 64 $res_json=json_decode(get_chepai($img_path,$tk), true, 512 , JSON_BIGINT_AS_STRING);//防止大数值转变成float类型 66 $car_num=$res_json["words_result"]["number"]; 67 $car_clolor=$res_json["words_result"]["color"]; 68 $car_real=$res_json["words_result"]["probability"]; 69 $car_log=$res_json["log_id"]; 70 echo floor($car_real[0]*100)/100; 71 echo $car_log; 72 var_dump($res_json); 73 print_r($res);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗