宝塔面板部署OCR

二级会员 站长
发表于Docker分类
1.修改镜像(https://docker.1ms.run),修改后面板自动重启


2.拉取线上镜像(c403/paddleocr),选择 c403/paddleocr:2.2.2-noavx


3.创建容器


4.部署成功


5.本服务器中使用:

function paddleOcrRecognize($imagePath = '', $url = '') { // 1. 准备请求数据 $postData = []; if (!empty($imagePath) && file_exists($imagePath)) { // 方式1:上传本地文件 $postData['img'] = curl_file_create($imagePath); } elseif (!empty($url)) { // 方式2:使用图片URL $postData['imgurl'] = $url; } else { return ['error' => '请提供本地图片路径或图片URL']; } $postData['outtype'] = 'json'; // 指定返回JSON格式 // 2. 初始化CURL请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:5000/ocr'); // 内网地址,速度快 curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时时间(秒) // 3. 执行请求并处理响应 $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { return ['error' => 'CURL请求失败: ' . $error]; } // 4. 解析JSON结果 $result = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { return ['error' => '解析JSON失败: ' . json_last_error_msg()]; } return $result; }


评论列表
加载更多
登录 分类