Przeglądaj źródła

Fix fastapi app bugs (#2527)

Lin Manhui 1 rok temu
rodzic
commit
415ce5c6c2

+ 52 - 40
docs/pipeline_usage/tutorials/ocr_pipelines/formula_recognition.en.md

@@ -411,9 +411,14 @@ Below are the API references and multi-language service invocation examples:
 <td>Positions and contents of formulas.</td>
 </tr>
 <tr>
-<td><code>image</code></td>
+<td><code>layoutImage</code></td>
 <td><code>string</code></td>
-<td>Formula recognition result image with detected formula positions annotated. The image is in JPEG format and encoded in Base64.</td>
+<td>Layout area detection result image. The image is in JPEG format and encoded using Base64.</td>
+</tr>
+<tr>
+<td><code>ocrImage</code></td>
+<td><code>string</code></td>
+<td>OCR result image. The image is in JPEG format and encoded using Base64.</td>
 </tr>
 </tbody>
 </table>
@@ -464,7 +469,8 @@ Below are the API references and multi-language service invocation examples:
 &quot;latex&quot;: &quot;F({\bf x})=C(F_{1}(x_{1}),\cdot\cdot\cdot,F_{N}(x_{N})).\qquad\qquad\qquad(1)&quot;
 }
 ],
-&quot;image&quot;: &quot;xxxxxx&quot;
+&quot;layoutImage&quot;: &quot;xxxxxx&quot;,
+&quot;ocrImage&quot;: &quot;xxxxxx&quot;
 }
 </code></pre></details>
 
@@ -479,7 +485,7 @@ import requests
 
 API_URL = &quot;http://localhost:8080/formula-recognition&quot;
 image_path = &quot;./demo.jpg&quot;
-output_image_path = &quot;./out.jpg&quot;
+layout_image_path = &quot;./layout.jpg&quot;
 
 with open(image_path, &quot;rb&quot;) as file:
     image_bytes = file.read()
@@ -491,9 +497,9 @@ response = requests.post(API_URL, json=payload)
 
 assert response.status_code == 200
 result = response.json()[&quot;result&quot;]
-with open(output_image_path, &quot;wb&quot;) as file:
-    file.write(base64.b64decode(result[&quot;image&quot;]))
-print(f&quot;Output image saved at {output_image_path}&quot;)
+with open(layout_image_path, &quot;wb&quot;) as file:
+    file.write(base64.b64decode(result[&quot;layoutImage&quot;]))
+print(f&quot;Output image saved at {layout_image_path}&quot;)
 print(&quot;\nDetected formulas:&quot;)
 print(result[&quot;formulas&quot;])
 </code></pre></details>
@@ -508,7 +514,7 @@ print(result[&quot;formulas&quot;])
 int main() {
     httplib::Client client(&quot;localhost:8080&quot;);
     const std::string imagePath = &quot;./demo.jpg&quot;;
-    const std::string outputImagePath = &quot;./out.jpg&quot;;
+    const std::string layoutImagePath = &quot;./layout.jpg&quot;;
 
     httplib::Headers headers = {
         {&quot;Content-Type&quot;, &quot;application/json&quot;}
@@ -535,16 +541,16 @@ int main() {
         nlohmann::json jsonResponse = nlohmann::json::parse(response-&gt;body);
         auto result = jsonResponse[&quot;result&quot;];
 
-        encodedImage = result[&quot;image&quot;];
-        std::string decodedString = base64::from_base64(encodedImage);
-        std::vector&lt;unsigned char&gt; decodedImage(decodedString.begin(), decodedString.end());
-        std::ofstream outputImage(outPutImagePath, std::ios::binary | std::ios::out);
-        if (outputImage.is_open()) {
-            outputImage.write(reinterpret_cast&lt;char*&gt;(decodedImage.data()), decodedImage.size());
-            outputImage.close();
-            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; outPutImagePath &lt;&lt; std::endl;
+        encodedImage = result[&quot;layoutImage&quot;];
+        decodedString = base64::from_base64(encodedImage);
+        std::vector&lt;unsigned char&gt; decodedLayoutImage(decodedString.begin(), decodedString.end());
+        std::ofstream outputLayoutFile(layoutImagePath, std::ios::binary | std::ios::out);
+        if (outputLayoutFile.is_open()) {
+            outputLayoutFile.write(reinterpret_cast&lt;char*&gt;(decodedLayoutImage.data()), decodedLayoutImage.size());
+            outputLayoutFile.close();
+            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         } else {
-            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; outPutImagePath &lt;&lt; std::endl;
+            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         }
 
         auto formulas = result[&quot;formulas&quot;];
@@ -577,7 +583,7 @@ public class Main {
     public static void main(String[] args) throws IOException {
         String API_URL = &quot;http://localhost:8080/formula-recognition&quot;;
         String imagePath = &quot;./demo.jpg&quot;;
-        String outputImagePath = &quot;./out.jpg&quot;;
+        String layoutImagePath = &quot;./layout.jpg&quot;;
 
         File file = new File(imagePath);
         byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
@@ -600,14 +606,15 @@ public class Main {
                 String responseBody = response.body().string();
                 JsonNode resultNode = objectMapper.readTree(responseBody);
                 JsonNode result = resultNode.get(&quot;result&quot;);
-                String base64Image = result.get(&quot;image&quot;).asText();
+                String layoutBase64Image = result.get(&quot;layoutImage&quot;).asText();
                 JsonNode formulas = result.get(&quot;formulas&quot;);
 
-                byte[] imageBytes = Base64.getDecoder().decode(base64Image);
-                try (FileOutputStream fos = new FileOutputStream(outputImagePath)) {
+                imageBytes = Base64.getDecoder().decode(layoutBase64Image);
+                try (FileOutputStream fos = new FileOutputStream(layoutImagePath)) {
                     fos.write(imageBytes);
                 }
-                System.out.println(&quot;Output image saved at &quot; + outputImagePath);
+                System.out.println(&quot;Output image saved at &quot; + layoutImagePath);
+
                 System.out.println(&quot;\nDetected formulas: &quot; + formulas.toString());
             } else {
                 System.err.println(&quot;Request failed with code: &quot; + response.code());
@@ -633,7 +640,7 @@ import (
 func main() {
     API_URL := &quot;http://localhost:8080/formula-recognition&quot;
     imagePath := &quot;./demo.jpg&quot;
-    outputImagePath := &quot;./out.jpg&quot;
+    layoutImagePath := &quot;./layout.jpg&quot;
 
     imageBytes, err := ioutil.ReadFile(imagePath)
     if err != nil {
@@ -670,7 +677,7 @@ func main() {
     }
     type Response struct {
         Result struct {
-            Image      string   `json:&quot;image&quot;`
+            LayoutImage      string   `json:&quot;layoutImage&quot;`
             Formulas []map[string]interface{} `json:&quot;formulas&quot;`
         } `json:&quot;result&quot;`
     }
@@ -681,17 +688,18 @@ func main() {
         return
     }
 
-    outputImageData, err := base64.StdEncoding.DecodeString(respData.Result.Image)
+    layoutImageData, err := base64.StdEncoding.DecodeString(respData.Result.LayoutImage)
     if err != nil {
         fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
         return
     }
-    err = ioutil.WriteFile(outputImagePath, outputImageData, 0644)
+    err = ioutil.WriteFile(layoutImagePath, layoutImageData, 0644)
     if err != nil {
         fmt.Println(&quot;Error writing image to file:&quot;, err)
         return
     }
-    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, outputImagePath)
+    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, layoutImagePath)
+
     fmt.Println(&quot;\nDetected formulas:&quot;)
     for _, formula := range respData.Result.Formulas {
         fmt.Println(formula)
@@ -713,7 +721,7 @@ class Program
 {
     static readonly string API_URL = &quot;http://localhost:8080/formula-recognition&quot;;
     static readonly string imagePath = &quot;./demo.jpg&quot;;
-    static readonly string outputImagePath = &quot;./out.jpg&quot;;
+    static readonly string layoutImagePath = &quot;./layout.jpg&quot;;
 
     static async Task Main(string[] args)
     {
@@ -731,11 +739,11 @@ class Program
         string responseBody = await response.Content.ReadAsStringAsync();
         JObject jsonResponse = JObject.Parse(responseBody);
 
-        string base64Image = jsonResponse[&quot;result&quot;][&quot;image&quot;].ToString();
-        byte[] outputImageBytes = Convert.FromBase64String(base64Image);
+        string layoutBase64Image = jsonResponse[&quot;result&quot;][&quot;layoutImage&quot;].ToString();
+        byte[] layoutImageBytes = Convert.FromBase64String(layoutBase64Image);
+        File.WriteAllBytes(layoutImagePath, layoutImageBytes);
+        Console.WriteLine($&quot;Output image saved at {layoutImagePath}&quot;);
 
-        File.WriteAllBytes(outputImagePath, outputImageBytes);
-        Console.WriteLine($&quot;Output image saved at {outputImagePath}&quot;);
         Console.WriteLine(&quot;\nDetected formulas:&quot;);
         Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;formulas&quot;].ToString());
     }
@@ -749,7 +757,7 @@ const fs = require('fs');
 
 const API_URL = 'http://localhost:8080/formula-recognition'
 const imagePath = './demo.jpg'
-const outputImagePath = &quot;./out.jpg&quot;;
+const layoutImagePath = &quot;./layout.jpg&quot;;
 
 let config = {
    method: 'POST',
@@ -768,11 +776,13 @@ function encodeImageToBase64(filePath) {
 axios.request(config)
 .then((response) =&gt; {
     const result = response.data[&quot;result&quot;];
-    const imageBuffer = Buffer.from(result[&quot;image&quot;], 'base64');
-    fs.writeFile(outputImagePath, imageBuffer, (err) =&gt; {
+
+    imageBuffer = Buffer.from(result[&quot;layoutImage&quot;], 'base64');
+    fs.writeFile(layoutImagePath, imageBuffer, (err) =&gt; {
       if (err) throw err;
-      console.log(`Output image saved at ${outputImagePath}`);
+      console.log(`Output image saved at ${layoutImagePath}`);
     });
+
     console.log(&quot;\nDetected formulas:&quot;);
     console.log(result[&quot;formulas&quot;]);
 })
@@ -785,9 +795,9 @@ axios.request(config)
 
 <pre><code class="language-php">&lt;?php
 
-$API_URL = &quot;http://localhost:8080/formula-recognition&quot;;
+$API_URL = &quot;http://localhost:8080/formula-recognition&quot;
 $image_path = &quot;./demo.jpg&quot;;
-$output_image_path = &quot;./out.jpg&quot;;
+$layout_image_path = &quot;./layout.jpg&quot;
 
 $image_data = base64_encode(file_get_contents($image_path));
 $payload = array(&quot;image&quot; =&gt; $image_data);
@@ -801,8 +811,10 @@ $response = curl_exec($ch);
 curl_close($ch);
 
 $result = json_decode($response, true)[&quot;result&quot;];
-file_put_contents($output_image_path, base64_decode($result[&quot;image&quot;]));
-echo &quot;Output image saved at &quot; . $output_image_path . &quot;\n&quot;;
+
+file_put_contents($layout_image_path, base64_decode($result[&quot;layoutImage&quot;]));
+echo &quot;Output image saved at &quot; . $layout_image_path . &quot;\n&quot;;
+
 echo &quot;\nDetected formulas:\n&quot;;
 print_r($result[&quot;formulas&quot;]);
 

+ 51 - 39
docs/pipeline_usage/tutorials/ocr_pipelines/formula_recognition.md

@@ -412,9 +412,14 @@ for res in output:
 <td>公式位置和内容。</td>
 </tr>
 <tr>
-<td><code>image</code></td>
+<td><code>layoutImage</code></td>
 <td><code>string</code></td>
-<td>公式识别结果图,其中标注检测到的公式位置。图像为JPEG格式,使用Base64编码。</td>
+<td>版面区域检测结果图。图像为JPEG格式,使用Base64编码。</td>
+</tr>
+<tr>
+<td><code>ocrImage</code></td>
+<td><code>string</code></td>
+<td>OCR结果图。图像为JPEG格式,使用Base64编码。</td>
 </tr>
 </tbody>
 </table>
@@ -465,7 +470,8 @@ for res in output:
 &quot;latex&quot;: &quot;F({\bf x})=C(F_{1}(x_{1}),\cdot\cdot\cdot,F_{N}(x_{N})).\qquad\qquad\qquad(1)&quot;
 }
 ],
-&quot;image&quot;: &quot;xxxxxx&quot;
+&quot;layoutImage&quot;: &quot;xxxxxx&quot;,
+&quot;ocrImage&quot;: &quot;xxxxxx&quot;
 }
 </code></pre></details>
 
@@ -480,7 +486,7 @@ import requests
 
 API_URL = &quot;http://localhost:8080/formula-recognition&quot; # 服务URL
 image_path = &quot;./demo.jpg&quot;
-output_image_path = &quot;./out.jpg&quot;
+layout_image_path = &quot;./layout.jpg&quot;
 
 # 对本地图像进行Base64编码
 with open(image_path, &quot;rb&quot;) as file:
@@ -495,9 +501,9 @@ response = requests.post(API_URL, json=payload)
 # 处理接口返回数据
 assert response.status_code == 200
 result = response.json()[&quot;result&quot;]
-with open(output_image_path, &quot;wb&quot;) as file:
-    file.write(base64.b64decode(result[&quot;image&quot;]))
-print(f&quot;Output image saved at {output_image_path}&quot;)
+with open(layout_image_path, &quot;wb&quot;) as file:
+    file.write(base64.b64decode(result[&quot;layoutImage&quot;]))
+print(f&quot;Output image saved at {layout_image_path}&quot;)
 print(&quot;\nDetected formulas:&quot;)
 print(result[&quot;formulas&quot;])
 </code></pre></details>
@@ -512,7 +518,7 @@ print(result[&quot;formulas&quot;])
 int main() {
     httplib::Client client(&quot;localhost:8080&quot;);
     const std::string imagePath = &quot;./demo.jpg&quot;;
-    const std::string outputImagePath = &quot;./out.jpg&quot;;
+    const std::string layoutImagePath = &quot;./layout.jpg&quot;;
 
     httplib::Headers headers = {
         {&quot;Content-Type&quot;, &quot;application/json&quot;}
@@ -542,16 +548,16 @@ int main() {
         nlohmann::json jsonResponse = nlohmann::json::parse(response-&gt;body);
         auto result = jsonResponse[&quot;result&quot;];
 
-        encodedImage = result[&quot;image&quot;];
-        std::string decodedString = base64::from_base64(encodedImage);
-        std::vector&lt;unsigned char&gt; decodedImage(decodedString.begin(), decodedString.end());
-        std::ofstream outputImage(outPutImagePath, std::ios::binary | std::ios::out);
-        if (outputImage.is_open()) {
-            outputImage.write(reinterpret_cast&lt;char*&gt;(decodedImage.data()), decodedImage.size());
-            outputImage.close();
-            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; outPutImagePath &lt;&lt; std::endl;
+        encodedImage = result[&quot;layoutImage&quot;];
+        decodedString = base64::from_base64(encodedImage);
+        std::vector&lt;unsigned char&gt; decodedLayoutImage(decodedString.begin(), decodedString.end());
+        std::ofstream outputLayoutFile(layoutImagePath, std::ios::binary | std::ios::out);
+        if (outputLayoutFile.is_open()) {
+            outputLayoutFile.write(reinterpret_cast&lt;char*&gt;(decodedLayoutImage.data()), decodedLayoutImage.size());
+            outputLayoutFile.close();
+            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         } else {
-            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; outPutImagePath &lt;&lt; std::endl;
+            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         }
 
         auto formulas = result[&quot;formulas&quot;];
@@ -584,7 +590,7 @@ public class Main {
     public static void main(String[] args) throws IOException {
         String API_URL = &quot;http://localhost:8080/formula-recognition&quot;; // 服务URL
         String imagePath = &quot;./demo.jpg&quot;; // 本地图像
-        String outputImagePath = &quot;./out.jpg&quot;; // 输出图像
+        String layoutImagePath = &quot;./layout.jpg&quot;;
 
         // 对本地图像进行Base64编码
         File file = new File(imagePath);
@@ -610,14 +616,15 @@ public class Main {
                 String responseBody = response.body().string();
                 JsonNode resultNode = objectMapper.readTree(responseBody);
                 JsonNode result = resultNode.get(&quot;result&quot;);
-                String base64Image = result.get(&quot;image&quot;).asText();
+                String layoutBase64Image = result.get(&quot;layoutImage&quot;).asText();
                 JsonNode formulas = result.get(&quot;formulas&quot;);
 
-                byte[] imageBytes = Base64.getDecoder().decode(base64Image);
-                try (FileOutputStream fos = new FileOutputStream(outputImagePath)) {
+                imageBytes = Base64.getDecoder().decode(layoutBase64Image);
+                try (FileOutputStream fos = new FileOutputStream(layoutImagePath)) {
                     fos.write(imageBytes);
                 }
-                System.out.println(&quot;Output image saved at &quot; + outputImagePath);
+                System.out.println(&quot;Output image saved at &quot; + layoutImagePath);
+
                 System.out.println(&quot;\nDetected formulas: &quot; + formulas.toString());
             } else {
                 System.err.println(&quot;Request failed with code: &quot; + response.code());
@@ -643,7 +650,7 @@ import (
 func main() {
     API_URL := &quot;http://localhost:8080/formula-recognition&quot;
     imagePath := &quot;./demo.jpg&quot;
-    outputImagePath := &quot;./out.jpg&quot;
+    layoutImagePath := &quot;./layout.jpg&quot;
 
     // 对本地图像进行Base64编码
     imageBytes, err := ioutil.ReadFile(imagePath)
@@ -683,7 +690,7 @@ func main() {
     }
     type Response struct {
         Result struct {
-            Image      string   `json:&quot;image&quot;`
+            LayoutImage      string   `json:&quot;layoutImage&quot;`
             Formulas []map[string]interface{} `json:&quot;formulas&quot;`
         } `json:&quot;result&quot;`
     }
@@ -694,17 +701,18 @@ func main() {
         return
     }
 
-    outputImageData, err := base64.StdEncoding.DecodeString(respData.Result.Image)
+    layoutImageData, err := base64.StdEncoding.DecodeString(respData.Result.LayoutImage)
     if err != nil {
         fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
         return
     }
-    err = ioutil.WriteFile(outputImagePath, outputImageData, 0644)
+    err = ioutil.WriteFile(layoutImagePath, layoutImageData, 0644)
     if err != nil {
         fmt.Println(&quot;Error writing image to file:&quot;, err)
         return
     }
-    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, outputImagePath)
+    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, layoutImagePath)
+
     fmt.Println(&quot;\nDetected formulas:&quot;)
     for _, formula := range respData.Result.Formulas {
         fmt.Println(formula)
@@ -726,7 +734,7 @@ class Program
 {
     static readonly string API_URL = &quot;http://localhost:8080/formula-recognition&quot;;
     static readonly string imagePath = &quot;./demo.jpg&quot;;
-    static readonly string outputImagePath = &quot;./out.jpg&quot;;
+    static readonly string layoutImagePath = &quot;./layout.jpg&quot;;
 
     static async Task Main(string[] args)
     {
@@ -747,11 +755,11 @@ class Program
         string responseBody = await response.Content.ReadAsStringAsync();
         JObject jsonResponse = JObject.Parse(responseBody);
 
-        string base64Image = jsonResponse[&quot;result&quot;][&quot;image&quot;].ToString();
-        byte[] outputImageBytes = Convert.FromBase64String(base64Image);
+        string layoutBase64Image = jsonResponse[&quot;result&quot;][&quot;layoutImage&quot;].ToString();
+        byte[] layoutImageBytes = Convert.FromBase64String(layoutBase64Image);
+        File.WriteAllBytes(layoutImagePath, layoutImageBytes);
+        Console.WriteLine($&quot;Output image saved at {layoutImagePath}&quot;);
 
-        File.WriteAllBytes(outputImagePath, outputImageBytes);
-        Console.WriteLine($&quot;Output image saved at {outputImagePath}&quot;);
         Console.WriteLine(&quot;\nDetected formulas:&quot;);
         Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;formulas&quot;].ToString());
     }
@@ -765,7 +773,7 @@ const fs = require('fs');
 
 const API_URL = 'http://localhost:8080/formula-recognition'
 const imagePath = './demo.jpg'
-const outputImagePath = &quot;./out.jpg&quot;;
+const layoutImagePath = &quot;./layout.jpg&quot;;
 
 let config = {
    method: 'POST',
@@ -787,11 +795,13 @@ axios.request(config)
 .then((response) =&gt; {
     // 处理接口返回数据
     const result = response.data[&quot;result&quot;];
-    const imageBuffer = Buffer.from(result[&quot;image&quot;], 'base64');
-    fs.writeFile(outputImagePath, imageBuffer, (err) =&gt; {
+
+    imageBuffer = Buffer.from(result[&quot;layoutImage&quot;], 'base64');
+    fs.writeFile(layoutImagePath, imageBuffer, (err) =&gt; {
       if (err) throw err;
-      console.log(`Output image saved at ${outputImagePath}`);
+      console.log(`Output image saved at ${layoutImagePath}`);
     });
+
     console.log(&quot;\nDetected formulas:&quot;);
     console.log(result[&quot;formulas&quot;]);
 })
@@ -806,7 +816,7 @@ axios.request(config)
 
 $API_URL = &quot;http://localhost:8080/formula-recognition&quot;; // 服务URL
 $image_path = &quot;./demo.jpg&quot;;
-$output_image_path = &quot;./out.jpg&quot;;
+$layout_image_path = &quot;./layout.jpg&quot;;
 
 // 对本地图像进行Base64编码
 $image_data = base64_encode(file_get_contents($image_path));
@@ -823,8 +833,10 @@ curl_close($ch);
 
 // 处理接口返回数据
 $result = json_decode($response, true)[&quot;result&quot;];
-file_put_contents($output_image_path, base64_decode($result[&quot;image&quot;]));
-echo &quot;Output image saved at &quot; . $output_image_path . &quot;\n&quot;;
+
+file_put_contents($layout_image_path, base64_decode($result[&quot;layoutImage&quot;]));
+echo &quot;Output image saved at &quot; . $layout_image_path . &quot;\n&quot;;
+
 echo &quot;\nDetected formulas:\n&quot;;
 print_r($result[&quot;formulas&quot;]);
 

+ 81 - 21
docs/pipeline_usage/tutorials/ocr_pipelines/seal_recognition.en.md

@@ -555,18 +555,23 @@ Below are the API references and multi-language service invocation examples:
 </thead>
 <tbody>
 <tr>
-<td><code>sealImpressions</code></td>
+<td><code>texts</code></td>
 <td><code>array</code></td>
-<td>Seal recognition results.</td>
+<td>Positions, contents, and scores of texts.</td>
 </tr>
 <tr>
 <td><code>layoutImage</code></td>
 <td><code>string</code></td>
 <td>Layout area detection result image. The image is in JPEG format and encoded using Base64.</td>
 </tr>
+<tr>
+<td><code>ocrImage</code></td>
+<td><code>string</code></td>
+<td>OCR result image. The image is in JPEG format and encoded using Base64.</td>
+</tr>
 </tbody>
 </table>
-<p>Each element in <code>sealImpressions</code> is an <code>object</code> with the following properties:</p>
+<p>Each element in <code>texts</code> is an <code>object</code> with the following properties:</p>
 <table>
 <thead>
 <tr>
@@ -605,6 +610,7 @@ import requests
 
 API_URL = &quot;http://localhost:8080/seal-recognition&quot;
 image_path = &quot;./demo.jpg&quot;
+ocr_image_path = &quot;./ocr.jpg&quot;
 layout_image_path = &quot;./layout.jpg&quot;
 
 with open(image_path, &quot;rb&quot;) as file:
@@ -617,11 +623,14 @@ response = requests.post(API_URL, json=payload)
 
 assert response.status_code == 200
 result = response.json()[&quot;result&quot;]
+with open(ocr_image_path, &quot;wb&quot;) as file:
+    file.write(base64.b64decode(result[&quot;ocrImage&quot;]))
+print(f&quot;Output image saved at {ocr_image_path}&quot;)
 with open(layout_image_path, &quot;wb&quot;) as file:
     file.write(base64.b64decode(result[&quot;layoutImage&quot;]))
 print(f&quot;Output image saved at {layout_image_path}&quot;)
-print(&quot;\nDetected seal impressions:&quot;)
-print(result[&quot;sealImpressions&quot;])
+print(&quot;\nDetected texts:&quot;)
+print(result[&quot;texts&quot;])
 </code></pre></details>
 
 <details><summary>C++</summary>
@@ -634,6 +643,7 @@ print(result[&quot;sealImpressions&quot;])
 int main() {
     httplib::Client client(&quot;localhost:8080&quot;);
     const std::string imagePath = &quot;./demo.jpg&quot;;
+    const std::string ocrImagePath = &quot;./ocr.jpg&quot;;
     const std::string layoutImagePath = &quot;./layout.jpg&quot;;
 
     httplib::Headers headers = {
@@ -661,6 +671,18 @@ int main() {
         nlohmann::json jsonResponse = nlohmann::json::parse(response-&gt;body);
         auto result = jsonResponse[&quot;result&quot;];
 
+        encodedImage = result[&quot;ocrImage&quot;];
+        std::string decoded_string = base64::from_base64(encodedImage);
+        std::vector&lt;unsigned char&gt; decodedOcrImage(decoded_string.begin(), decoded_string.end());
+        std::ofstream outputOcrFile(ocrImagePath, std::ios::binary | std::ios::out);
+        if (outputOcrFile.is_open()) {
+            outputOcrFile.write(reinterpret_cast&lt;char*&gt;(decodedOcrImage.data()), decodedOcrImage.size());
+            outputOcrFile.close();
+            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; ocrImagePath &lt;&lt; std::endl;
+        } else {
+            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; ocrImagePath &lt;&lt; std::endl;
+        }
+
         encodedImage = result[&quot;layoutImage&quot;];
         decodedString = base64::from_base64(encodedImage);
         std::vector&lt;unsigned char&gt; decodedLayoutImage(decodedString.begin(), decodedString.end());
@@ -673,10 +695,10 @@ int main() {
             std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         }
 
-        auto impressions = result[&quot;sealImpressions&quot;];
-        std::cout &lt;&lt; &quot;\nDetected seal impressions:&quot; &lt;&lt; std::endl;
-        for (const auto&amp; impression : impressions) {
-            std::cout &lt;&lt; impression &lt;&lt; std::endl;
+        auto texts = result[&quot;texts&quot;];
+        std::cout &lt;&lt; &quot;\nDetected texts:&quot; &lt;&lt; std::endl;
+        for (const auto&amp; text : texts) {
+            std::cout &lt;&lt; text &lt;&lt; std::endl;
         }
     } else {
         std::cout &lt;&lt; &quot;Failed to send HTTP request.&quot; &lt;&lt; std::endl;
@@ -703,6 +725,7 @@ public class Main {
     public static void main(String[] args) throws IOException {
         String API_URL = &quot;http://localhost:8080/seal-recognition&quot;;
         String imagePath = &quot;./demo.jpg&quot;;
+        String ocrImagePath = &quot;./ocr.jpg&quot;;
         String layoutImagePath = &quot;./layout.jpg&quot;;
 
         File file = new File(imagePath);
@@ -726,8 +749,15 @@ public class Main {
                 String responseBody = response.body().string();
                 JsonNode resultNode = objectMapper.readTree(responseBody);
                 JsonNode result = resultNode.get(&quot;result&quot;);
+                String ocrBase64Image = result.get(&quot;ocrImage&quot;).asText();
                 String layoutBase64Image = result.get(&quot;layoutImage&quot;).asText();
-                JsonNode impressions = result.get(&quot;sealImpressions&quot;);
+                JsonNode texts = result.get(&quot;texts&quot;);
+
+                byte[] imageBytes = Base64.getDecoder().decode(ocrBase64Image);
+                try (FileOutputStream fos = new FileOutputStream(ocrImagePath)) {
+                    fos.write(imageBytes);
+                }
+                System.out.println(&quot;Output image saved at &quot; + ocrBase64Image);
 
                 imageBytes = Base64.getDecoder().decode(layoutBase64Image);
                 try (FileOutputStream fos = new FileOutputStream(layoutImagePath)) {
@@ -735,7 +765,7 @@ public class Main {
                 }
                 System.out.println(&quot;Output image saved at &quot; + layoutImagePath);
 
-                System.out.println(&quot;\nDetected seal impressions: &quot; + impressions.toString());
+                System.out.println(&quot;\nDetected texts: &quot; + texts.toString());
             } else {
                 System.err.println(&quot;Request failed with code: &quot; + response.code());
             }
@@ -760,6 +790,7 @@ import (
 func main() {
     API_URL := &quot;http://localhost:8080/seal-recognition&quot;
     imagePath := &quot;./demo.jpg&quot;
+    ocrImagePath := &quot;./ocr.jpg&quot;
     layoutImagePath := &quot;./layout.jpg&quot;
 
     imageBytes, err := ioutil.ReadFile(imagePath)
@@ -797,8 +828,9 @@ func main() {
     }
     type Response struct {
         Result struct {
+            OcrImage      string   `json:&quot;ocrImage&quot;`
             LayoutImage      string   `json:&quot;layoutImage&quot;`
-            Impressions []map[string]interface{} `json:&quot;sealImpressions&quot;`
+            Texts []map[string]interface{} `json:&quot;texts&quot;`
         } `json:&quot;result&quot;`
     }
     var respData Response
@@ -808,6 +840,18 @@ func main() {
         return
     }
 
+    ocrImageData, err := base64.StdEncoding.DecodeString(respData.Result.OcrImage)
+    if err != nil {
+        fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
+        return
+    }
+    err = ioutil.WriteFile(ocrImagePath, ocrImageData, 0644)
+    if err != nil {
+        fmt.Println(&quot;Error writing image to file:&quot;, err)
+        return
+    }
+    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, ocrImagePath)
+
     layoutImageData, err := base64.StdEncoding.DecodeString(respData.Result.LayoutImage)
     if err != nil {
         fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
@@ -820,9 +864,9 @@ func main() {
     }
     fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, layoutImagePath)
 
-    fmt.Println(&quot;\nDetected seal impressions:&quot;)
-    for _, impression := range respData.Result.Impressions {
-        fmt.Println(impression)
+    fmt.Println(&quot;\nDetected texts:&quot;)
+    for _, text := range respData.Result.Texts {
+        fmt.Println(text)
     }
 }
 </code></pre></details>
@@ -841,6 +885,7 @@ class Program
 {
     static readonly string API_URL = &quot;http://localhost:8080/seal-recognition&quot;;
     static readonly string imagePath = &quot;./demo.jpg&quot;;
+    static readonly string ocrImagePath = &quot;./ocr.jpg&quot;;
     static readonly string layoutImagePath = &quot;./layout.jpg&quot;;
 
     static async Task Main(string[] args)
@@ -859,13 +904,18 @@ class Program
         string responseBody = await response.Content.ReadAsStringAsync();
         JObject jsonResponse = JObject.Parse(responseBody);
 
+        string ocrBase64Image = jsonResponse[&quot;result&quot;][&quot;ocrImage&quot;].ToString();
+        byte[] ocrImageBytes = Convert.FromBase64String(ocrBase64Image);
+        File.WriteAllBytes(ocrImagePath, ocrImageBytes);
+        Console.WriteLine($&quot;Output image saved at {ocrImagePath}&quot;);
+
         string layoutBase64Image = jsonResponse[&quot;result&quot;][&quot;layoutImage&quot;].ToString();
         byte[] layoutImageBytes = Convert.FromBase64String(layoutBase64Image);
         File.WriteAllBytes(layoutImagePath, layoutImageBytes);
         Console.WriteLine($&quot;Output image saved at {layoutImagePath}&quot;);
 
-        Console.WriteLine(&quot;\nDetected seal impressions:&quot;);
-        Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;sealImpressions&quot;].ToString());
+        Console.WriteLine(&quot;\nDetected texts:&quot;);
+        Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;texts&quot;].ToString());
     }
 }
 </code></pre></details>
@@ -877,6 +927,7 @@ const fs = require('fs');
 
 const API_URL = 'http://localhost:8080/seal-recognition'
 const imagePath = './demo.jpg'
+const ocrImagePath = &quot;./ocr.jpg&quot;;
 const layoutImagePath = &quot;./layout.jpg&quot;;
 
 let config = {
@@ -897,14 +948,20 @@ axios.request(config)
 .then((response) =&gt; {
     const result = response.data[&quot;result&quot;];
 
+    const imageBuffer = Buffer.from(result[&quot;ocrImage&quot;], 'base64');
+    fs.writeFile(ocrImagePath, imageBuffer, (err) =&gt; {
+      if (err) throw err;
+      console.log(`Output image saved at ${ocrImagePath}`);
+    });
+
     imageBuffer = Buffer.from(result[&quot;layoutImage&quot;], 'base64');
     fs.writeFile(layoutImagePath, imageBuffer, (err) =&gt; {
       if (err) throw err;
       console.log(`Output image saved at ${layoutImagePath}`);
     });
 
-    console.log(&quot;\nDetected seal impressions:&quot;);
-    console.log(result[&quot;sealImpressions&quot;]);
+    console.log(&quot;\nDetected texts:&quot;);
+    console.log(result[&quot;texts&quot;]);
 })
 .catch((error) =&gt; {
   console.log(error);
@@ -917,6 +974,7 @@ axios.request(config)
 
 $API_URL = &quot;http://localhost:8080/seal-recognition&quot;;
 $image_path = &quot;./demo.jpg&quot;;
+$ocr_image_path = &quot;./ocr.jpg&quot;;
 $layout_image_path = &quot;./layout.jpg&quot;;
 
 $image_data = base64_encode(file_get_contents($image_path));
@@ -931,12 +989,14 @@ $response = curl_exec($ch);
 curl_close($ch);
 
 $result = json_decode($response, true)[&quot;result&quot;];
+file_put_contents($ocr_image_path, base64_decode($result[&quot;ocrImage&quot;]));
+echo &quot;Output image saved at &quot; . $ocr_image_path . &quot;\n&quot;;
 
 file_put_contents($layout_image_path, base64_decode($result[&quot;layoutImage&quot;]));
 echo &quot;Output image saved at &quot; . $layout_image_path . &quot;\n&quot;;
 
-echo &quot;\nDetected seal impressions:\n&quot;;
-print_r($result[&quot;sealImpressions&quot;]);
+echo &quot;\nDetected texts:\n&quot;;
+print_r($result[&quot;texts&quot;]);
 
 ?&gt;
 </code></pre></details>

+ 78 - 35
docs/pipeline_usage/tutorials/ocr_pipelines/seal_recognition.md

@@ -565,31 +565,19 @@ for res in output:
 </thead>
 <tbody>
 <tr>
-<td><code>sealImpressions</code></td>
+<td><code>texts</code></td>
 <td><code>array</code></td>
-<td>印章文本识别结果。</td>
+<td>文本位置、内容和得分。</td>
 </tr>
 <tr>
 <td><code>layoutImage</code></td>
 <td><code>string</code></td>
 <td>版面区域检测结果图。图像为JPEG格式,使用Base64编码。</td>
 </tr>
-</tbody>
-</table>
-<p><code>sealImpressions</code>中的每个元素为一个<code>object</code>,具有如下属性:</p>
-<table>
-<thead>
-<tr>
-<th>名称</th>
-<th>类型</th>
-<th>含义</th>
-</tr>
-</thead>
-<tbody>
 <tr>
-<td><code>texts</code></td>
-<td><code>array</code></td>
-<td>文本位置、内容和得分。</td>
+<td><code>ocrImage</code></td>
+<td><code>string</code></td>
+<td>OCR结果图。图像为JPEG格式,使用Base64编码。</td>
 </tr>
 </tbody>
 </table>
@@ -632,6 +620,7 @@ import requests
 
 API_URL = &quot;http://localhost:8080/seal-recognition&quot; # 服务URL
 image_path = &quot;./demo.jpg&quot;
+ocr_image_path = &quot;./ocr.jpg&quot;
 layout_image_path = &quot;./layout.jpg&quot;
 
 # 对本地图像进行Base64编码
@@ -647,11 +636,14 @@ response = requests.post(API_URL, json=payload)
 # 处理接口返回数据
 assert response.status_code == 200
 result = response.json()[&quot;result&quot;]
+with open(ocr_image_path, &quot;wb&quot;) as file:
+    file.write(base64.b64decode(result[&quot;ocrImage&quot;]))
+print(f&quot;Output image saved at {ocr_image_path}&quot;)
 with open(layout_image_path, &quot;wb&quot;) as file:
     file.write(base64.b64decode(result[&quot;layoutImage&quot;]))
 print(f&quot;Output image saved at {layout_image_path}&quot;)
-print(&quot;\nDetected seal impressions:&quot;)
-print(result[&quot;sealImpressions&quot;])
+print(&quot;\nDetected texts:&quot;)
+print(result[&quot;texts&quot;])
 </code></pre></details>
 
 <details><summary>C++</summary>
@@ -664,6 +656,7 @@ print(result[&quot;sealImpressions&quot;])
 int main() {
     httplib::Client client(&quot;localhost:8080&quot;);
     const std::string imagePath = &quot;./demo.jpg&quot;;
+    const std::string ocrImagePath = &quot;./ocr.jpg&quot;;
     const std::string layoutImagePath = &quot;./layout.jpg&quot;;
 
     httplib::Headers headers = {
@@ -694,6 +687,18 @@ int main() {
         nlohmann::json jsonResponse = nlohmann::json::parse(response-&gt;body);
         auto result = jsonResponse[&quot;result&quot;];
 
+        encodedImage = result[&quot;ocrImage&quot;];
+        std::string decoded_string = base64::from_base64(encodedImage);
+        std::vector&lt;unsigned char&gt; decodedOcrImage(decoded_string.begin(), decoded_string.end());
+        std::ofstream outputOcrFile(ocrImagePath, std::ios::binary | std::ios::out);
+        if (outputOcrFile.is_open()) {
+            outputOcrFile.write(reinterpret_cast&lt;char*&gt;(decodedOcrImage.data()), decodedOcrImage.size());
+            outputOcrFile.close();
+            std::cout &lt;&lt; &quot;Output image saved at &quot; &lt;&lt; ocrImagePath &lt;&lt; std::endl;
+        } else {
+            std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; ocrImagePath &lt;&lt; std::endl;
+        }
+
         encodedImage = result[&quot;layoutImage&quot;];
         decodedString = base64::from_base64(encodedImage);
         std::vector&lt;unsigned char&gt; decodedLayoutImage(decodedString.begin(), decodedString.end());
@@ -706,10 +711,10 @@ int main() {
             std::cerr &lt;&lt; &quot;Unable to open file for writing: &quot; &lt;&lt; layoutImagePath &lt;&lt; std::endl;
         }
 
-        auto impressions = result[&quot;sealImpressions&quot;];
-        std::cout &lt;&lt; &quot;\nDetected seal impressions:&quot; &lt;&lt; std::endl;
-        for (const auto&amp; impression : impressions) {
-            std::cout &lt;&lt; impression &lt;&lt; std::endl;
+        auto texts = result[&quot;texts&quot;];
+        std::cout &lt;&lt; &quot;\nDetected texts:&quot; &lt;&lt; std::endl;
+        for (const auto&amp; text : texts) {
+            std::cout &lt;&lt; text &lt;&lt; std::endl;
         }
     } else {
         std::cout &lt;&lt; &quot;Failed to send HTTP request.&quot; &lt;&lt; std::endl;
@@ -736,6 +741,7 @@ public class Main {
     public static void main(String[] args) throws IOException {
         String API_URL = &quot;http://localhost:8080/seal-recognition&quot;; // 服务URL
         String imagePath = &quot;./demo.jpg&quot;; // 本地图像
+        String ocrImagePath = &quot;./ocr.jpg&quot;;
         String layoutImagePath = &quot;./layout.jpg&quot;;
 
         // 对本地图像进行Base64编码
@@ -762,8 +768,15 @@ public class Main {
                 String responseBody = response.body().string();
                 JsonNode resultNode = objectMapper.readTree(responseBody);
                 JsonNode result = resultNode.get(&quot;result&quot;);
+                String ocrBase64Image = result.get(&quot;ocrImage&quot;).asText();
                 String layoutBase64Image = result.get(&quot;layoutImage&quot;).asText();
-                JsonNode impressions = result.get(&quot;sealImpressions&quot;);
+                JsonNode texts = result.get(&quot;texts&quot;);
+
+                byte[] imageBytes = Base64.getDecoder().decode(ocrBase64Image);
+                try (FileOutputStream fos = new FileOutputStream(ocrImagePath)) {
+                    fos.write(imageBytes);
+                }
+                System.out.println(&quot;Output image saved at &quot; + ocrBase64Image);
 
                 imageBytes = Base64.getDecoder().decode(layoutBase64Image);
                 try (FileOutputStream fos = new FileOutputStream(layoutImagePath)) {
@@ -771,7 +784,7 @@ public class Main {
                 }
                 System.out.println(&quot;Output image saved at &quot; + layoutImagePath);
 
-                System.out.println(&quot;\nDetected seal impressions: &quot; + impressions.toString());
+                System.out.println(&quot;\nDetected texts: &quot; + texts.toString());
             } else {
                 System.err.println(&quot;Request failed with code: &quot; + response.code());
             }
@@ -796,6 +809,7 @@ import (
 func main() {
     API_URL := &quot;http://localhost:8080/seal-recognition&quot;
     imagePath := &quot;./demo.jpg&quot;
+    ocrImagePath := &quot;./ocr.jpg&quot;
     layoutImagePath := &quot;./layout.jpg&quot;
 
     // 对本地图像进行Base64编码
@@ -836,8 +850,9 @@ func main() {
     }
     type Response struct {
         Result struct {
+            OcrImage      string   `json:&quot;ocrImage&quot;`
             LayoutImage      string   `json:&quot;layoutImage&quot;`
-            Impressions []map[string]interface{} `json:&quot;sealImpressions&quot;`
+            Texts []map[string]interface{} `json:&quot;texts&quot;`
         } `json:&quot;result&quot;`
     }
     var respData Response
@@ -847,6 +862,18 @@ func main() {
         return
     }
 
+    ocrImageData, err := base64.StdEncoding.DecodeString(respData.Result.OcrImage)
+    if err != nil {
+        fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
+        return
+    }
+    err = ioutil.WriteFile(ocrImagePath, ocrImageData, 0644)
+    if err != nil {
+        fmt.Println(&quot;Error writing image to file:&quot;, err)
+        return
+    }
+    fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, ocrImagePath)
+
     layoutImageData, err := base64.StdEncoding.DecodeString(respData.Result.LayoutImage)
     if err != nil {
         fmt.Println(&quot;Error decoding base64 image data:&quot;, err)
@@ -859,9 +886,9 @@ func main() {
     }
     fmt.Printf(&quot;Image saved at %s.jpg\n&quot;, layoutImagePath)
 
-    fmt.Println(&quot;\nDetected seal impressions:&quot;)
-    for _, impression := range respData.Result.Impressions {
-        fmt.Println(impression)
+    fmt.Println(&quot;\nDetected texts:&quot;)
+    for _, text := range respData.Result.Texts {
+        fmt.Println(text)
     }
 }
 </code></pre></details>
@@ -880,6 +907,7 @@ class Program
 {
     static readonly string API_URL = &quot;http://localhost:8080/seal-recognition&quot;;
     static readonly string imagePath = &quot;./demo.jpg&quot;;
+    static readonly string ocrImagePath = &quot;./ocr.jpg&quot;;
     static readonly string layoutImagePath = &quot;./layout.jpg&quot;;
 
     static async Task Main(string[] args)
@@ -901,13 +929,18 @@ class Program
         string responseBody = await response.Content.ReadAsStringAsync();
         JObject jsonResponse = JObject.Parse(responseBody);
 
+        string ocrBase64Image = jsonResponse[&quot;result&quot;][&quot;ocrImage&quot;].ToString();
+        byte[] ocrImageBytes = Convert.FromBase64String(ocrBase64Image);
+        File.WriteAllBytes(ocrImagePath, ocrImageBytes);
+        Console.WriteLine($&quot;Output image saved at {ocrImagePath}&quot;);
+
         string layoutBase64Image = jsonResponse[&quot;result&quot;][&quot;layoutImage&quot;].ToString();
         byte[] layoutImageBytes = Convert.FromBase64String(layoutBase64Image);
         File.WriteAllBytes(layoutImagePath, layoutImageBytes);
         Console.WriteLine($&quot;Output image saved at {layoutImagePath}&quot;);
 
-        Console.WriteLine(&quot;\nDetected seal impressions:&quot;);
-        Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;sealImpressions&quot;].ToString());
+        Console.WriteLine(&quot;\nDetected texts:&quot;);
+        Console.WriteLine(jsonResponse[&quot;result&quot;][&quot;texts&quot;].ToString());
     }
 }
 </code></pre></details>
@@ -919,6 +952,7 @@ const fs = require('fs');
 
 const API_URL = 'http://localhost:8080/seal-recognition'
 const imagePath = './demo.jpg'
+const ocrImagePath = &quot;./ocr.jpg&quot;;
 const layoutImagePath = &quot;./layout.jpg&quot;;
 
 let config = {
@@ -942,14 +976,20 @@ axios.request(config)
     // 处理接口返回数据
     const result = response.data[&quot;result&quot;];
 
+    const imageBuffer = Buffer.from(result[&quot;ocrImage&quot;], 'base64');
+    fs.writeFile(ocrImagePath, imageBuffer, (err) =&gt; {
+      if (err) throw err;
+      console.log(`Output image saved at ${ocrImagePath}`);
+    });
+
     imageBuffer = Buffer.from(result[&quot;layoutImage&quot;], 'base64');
     fs.writeFile(layoutImagePath, imageBuffer, (err) =&gt; {
       if (err) throw err;
       console.log(`Output image saved at ${layoutImagePath}`);
     });
 
-    console.log(&quot;\nDetected seal impressions:&quot;);
-    console.log(result[&quot;sealImpressions&quot;]);
+    console.log(&quot;\nDetected texts:&quot;);
+    console.log(result[&quot;texts&quot;]);
 })
 .catch((error) =&gt; {
   console.log(error);
@@ -962,6 +1002,7 @@ axios.request(config)
 
 $API_URL = &quot;http://localhost:8080/seal-recognition&quot;; // 服务URL
 $image_path = &quot;./demo.jpg&quot;;
+$ocr_image_path = &quot;./ocr.jpg&quot;;
 $layout_image_path = &quot;./layout.jpg&quot;;
 
 // 对本地图像进行Base64编码
@@ -979,12 +1020,14 @@ curl_close($ch);
 
 // 处理接口返回数据
 $result = json_decode($response, true)[&quot;result&quot;];
+file_put_contents($ocr_image_path, base64_decode($result[&quot;ocrImage&quot;]));
+echo &quot;Output image saved at &quot; . $ocr_image_path . &quot;\n&quot;;
 
 file_put_contents($layout_image_path, base64_decode($result[&quot;layoutImage&quot;]));
 echo &quot;Output image saved at &quot; . $layout_image_path . &quot;\n&quot;;
 
-echo &quot;\nDetected seal impressions:\n&quot;;
-print_r($result[&quot;sealImpressions&quot;]);
+echo &quot;\nDetected texts:\n&quot;;
+print_r($result[&quot;texts&quot;]);
 
 ?&gt;
 </code></pre></details>

+ 14 - 4
paddlex/inference/pipelines/serving/_pipeline_apps/formula_recognition.py

@@ -45,7 +45,8 @@ class Formula(BaseModel):
 
 class InferResult(BaseModel):
     formulas: List[Formula]
-    image: str
+    layoutImage: str
+    ocrImage: Optional[str] = None
 
 
 def create_pipeline_app(
@@ -59,6 +60,7 @@ def create_pipeline_app(
         "/formula-recognition",
         operation_id="infer",
         responses={422: {"model": Response}},
+        response_model_exclude_none=True,
     )
     async def _infer(request: InferRequest) -> ResultResponse[InferResult]:
         pipeline = ctx.pipeline
@@ -88,9 +90,16 @@ def create_pipeline_app(
                         latex=latex,
                     )
                 )
-            output_image_base64 = serving_utils.base64_encode(
-                serving_utils.image_to_bytes(result.img)
+            layout_image_base64 = serving_utils.base64_encode(
+                serving_utils.image_to_bytes(result["layout_result"].img)
             )
+            ocr_image = result["formula_result"].img
+            if ocr_image is not None:
+                ocr_image_base64 = serving_utils.base64_encode(
+                    serving_utils.image_to_bytes(ocr_image)
+                )
+            else:
+                ocr_image_base64 = None
 
             return ResultResponse(
                 logId=serving_utils.generate_log_id(),
@@ -98,7 +107,8 @@ def create_pipeline_app(
                 errorMsg="Success",
                 result=InferResult(
                     formulas=formulas,
-                    image=output_image_base64,
+                    layoutImage=layout_image_base64,
+                    ocrImage=ocr_image_base64,
                 ),
             )
 

+ 14 - 16
paddlex/inference/pipelines/serving/_pipeline_apps/seal_recognition.py

@@ -44,13 +44,10 @@ class Text(BaseModel):
     score: float
 
 
-class SealImpression(BaseModel):
-    texts: List[Text]
-
-
 class InferResult(BaseModel):
-    sealImpressions: List[SealImpression]
+    texts: List[Text]
     layoutImage: str
+    ocrImage: str
 
 
 def create_pipeline_app(pipeline: SealOCRPipeline, app_config: AppConfig) -> FastAPI:
@@ -81,27 +78,28 @@ def create_pipeline_app(pipeline: SealOCRPipeline, app_config: AppConfig) -> Fas
 
             result = (await pipeline.infer(image))[0]
 
-            seal_impressions: List[SealImpression] = []
-            for item in result["ocr_result"]:
-                texts: List[Text] = []
-                for poly, text, score in zip(
-                    item["dt_polys"], item["rec_text"], item["rec_score"]
-                ):
-                    texts.append(Text(poly=poly, text=text, score=score))
-                seal_impressions.append(SealImpression(texts=texts))
+            texts: List[Text] = []
+            for poly, text, score in zip(
+                result["ocr_result"]["dt_polys"],
+                result["ocr_result"]["rec_text"],
+                result["ocr_result"]["rec_score"],
+            ):
+                texts.append(Text(poly=poly, text=text, score=score))
             layout_image_base64 = serving_utils.base64_encode(
                 serving_utils.image_to_bytes(result["layout_result"].img)
             )
-
-            # TODO: OCR image
+            ocr_image_base64 = serving_utils.base64_encode(
+                serving_utils.image_to_bytes(result["ocr_result"].img)
+            )
 
             return ResultResponse(
                 logId=serving_utils.generate_log_id(),
                 errorCode=0,
                 errorMsg="Success",
                 result=InferResult(
-                    sealImpressions=seal_impressions,
+                    texts=texts,
                     layoutImage=layout_image_base64,
+                    ocrImage=ocr_image_base64,
                 ),
             )
 

+ 2 - 2
paddlex/inference/pipelines/serving/_pipeline_apps/table_recognition.py

@@ -88,7 +88,7 @@ def create_pipeline_app(pipeline: TableRecPipeline, app_config: AppConfig) -> Fa
             layout_image_base64 = serving_utils.base64_encode(
                 serving_utils.image_to_bytes(result["layout_result"].img)
             )
-            ocr_iamge_base64 = serving_utils.base64_encode(
+            ocr_image_base64 = serving_utils.base64_encode(
                 serving_utils.image_to_bytes(result["ocr_result"].img)
             )
 
@@ -99,7 +99,7 @@ def create_pipeline_app(pipeline: TableRecPipeline, app_config: AppConfig) -> Fa
                 result=InferResult(
                     tables=tables,
                     layoutImage=layout_image_base64,
-                    ocrImage=ocr_iamge_base64,
+                    ocrImage=ocr_image_base64,
                 ),
             )