# paddle_ocr_service **Repository Path**: flying_red_pig/paddle_ocr_service ## Basic Information - **Project Name**: paddle_ocr_service - **Description**: 为 paddle ocr 提供一个以 docker 为基础的 web 服务 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-25 - **Last Updated**: 2025-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UI5 OCR Service API The OCR API allows you to extract text from images using Optical Character Recognition (OCR) technology. Send a POST request with an image file and receive the extracted text in the response. ## Endpoint ``` POST http://{HOST_URL}:8080/ocr ``` ## Request ### Headers - `Content-Type`: multipart/form-data; boundary=your_boundary_here ### Body - `file`: The image file you want to extract text from. Supported formats include JPEG, PNG, and GIF. - `data`: A JSON object containing additional information for the OCR process. Currently, only the language parameter is supported. Example: ```json { "lang": "en" } ``` #### data parameters 1. `lang` (optional): The language used for OCR processing. Default is `'en'` (English). You can pass any language supported by the `PaddleOCR` class. The parameters detail please check `https://github.com/Mushroomcat9998/PaddleOCR/blob/main/doc/doc_en/multi_languages_en.md#language_abbreviations`. ## Response The API will respond with a JSON object containing the extracted text. ### Success If the OCR process is successful, the response will have a `message` field containing the extracted text. Example: ```json { "message": [ "Extracted text from the image" ] } ``` ### Failure - Status code: `400` - Content-Type: `application/json` - Body: A JSON object containing the error message. ## Example Usage Here is an example of using the OCR API with JavaScript and Axios: ```javascript const axios = require('axios'); const FormData = require('form-data'); const fs = require('fs'); async function uploadImage(imagePath) { const formData = new FormData(); const data = { lang: 'en' }; formData.append('file', fs.createReadStream(imagePath)); formData.append('data', JSON.stringify(data)); try { const response = await axios.post('http://localhost:8080/ocr', formData, { headers: { 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`, }, }); console.log('Upload success:', response.data.message[0]); } catch (error) { console.error('Upload failed:', error.response); } } const imagePath = './img2.png'; uploadImage(imagePath); ``` ## Deploy ```shell docker-compose up ```