|
|
@@ -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 = "http://localhost:8080/seal-recognition"
|
|
|
image_path = "./demo.jpg"
|
|
|
+ocr_image_path = "./ocr.jpg"
|
|
|
layout_image_path = "./layout.jpg"
|
|
|
|
|
|
with open(image_path, "rb") as file:
|
|
|
@@ -617,11 +623,14 @@ response = requests.post(API_URL, json=payload)
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
result = response.json()["result"]
|
|
|
+with open(ocr_image_path, "wb") as file:
|
|
|
+ file.write(base64.b64decode(result["ocrImage"]))
|
|
|
+print(f"Output image saved at {ocr_image_path}")
|
|
|
with open(layout_image_path, "wb") as file:
|
|
|
file.write(base64.b64decode(result["layoutImage"]))
|
|
|
print(f"Output image saved at {layout_image_path}")
|
|
|
-print("\nDetected seal impressions:")
|
|
|
-print(result["sealImpressions"])
|
|
|
+print("\nDetected texts:")
|
|
|
+print(result["texts"])
|
|
|
</code></pre></details>
|
|
|
|
|
|
<details><summary>C++</summary>
|
|
|
@@ -634,6 +643,7 @@ print(result["sealImpressions"])
|
|
|
int main() {
|
|
|
httplib::Client client("localhost:8080");
|
|
|
const std::string imagePath = "./demo.jpg";
|
|
|
+ const std::string ocrImagePath = "./ocr.jpg";
|
|
|
const std::string layoutImagePath = "./layout.jpg";
|
|
|
|
|
|
httplib::Headers headers = {
|
|
|
@@ -661,6 +671,18 @@ int main() {
|
|
|
nlohmann::json jsonResponse = nlohmann::json::parse(response->body);
|
|
|
auto result = jsonResponse["result"];
|
|
|
|
|
|
+ encodedImage = result["ocrImage"];
|
|
|
+ std::string decoded_string = base64::from_base64(encodedImage);
|
|
|
+ std::vector<unsigned char> 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<char*>(decodedOcrImage.data()), decodedOcrImage.size());
|
|
|
+ outputOcrFile.close();
|
|
|
+ std::cout << "Output image saved at " << ocrImagePath << std::endl;
|
|
|
+ } else {
|
|
|
+ std::cerr << "Unable to open file for writing: " << ocrImagePath << std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
encodedImage = result["layoutImage"];
|
|
|
decodedString = base64::from_base64(encodedImage);
|
|
|
std::vector<unsigned char> decodedLayoutImage(decodedString.begin(), decodedString.end());
|
|
|
@@ -673,10 +695,10 @@ int main() {
|
|
|
std::cerr << "Unable to open file for writing: " << layoutImagePath << std::endl;
|
|
|
}
|
|
|
|
|
|
- auto impressions = result["sealImpressions"];
|
|
|
- std::cout << "\nDetected seal impressions:" << std::endl;
|
|
|
- for (const auto& impression : impressions) {
|
|
|
- std::cout << impression << std::endl;
|
|
|
+ auto texts = result["texts"];
|
|
|
+ std::cout << "\nDetected texts:" << std::endl;
|
|
|
+ for (const auto& text : texts) {
|
|
|
+ std::cout << text << std::endl;
|
|
|
}
|
|
|
} else {
|
|
|
std::cout << "Failed to send HTTP request." << std::endl;
|
|
|
@@ -703,6 +725,7 @@ public class Main {
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
String API_URL = "http://localhost:8080/seal-recognition";
|
|
|
String imagePath = "./demo.jpg";
|
|
|
+ String ocrImagePath = "./ocr.jpg";
|
|
|
String layoutImagePath = "./layout.jpg";
|
|
|
|
|
|
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("result");
|
|
|
+ String ocrBase64Image = result.get("ocrImage").asText();
|
|
|
String layoutBase64Image = result.get("layoutImage").asText();
|
|
|
- JsonNode impressions = result.get("sealImpressions");
|
|
|
+ JsonNode texts = result.get("texts");
|
|
|
+
|
|
|
+ byte[] imageBytes = Base64.getDecoder().decode(ocrBase64Image);
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(ocrImagePath)) {
|
|
|
+ fos.write(imageBytes);
|
|
|
+ }
|
|
|
+ System.out.println("Output image saved at " + ocrBase64Image);
|
|
|
|
|
|
imageBytes = Base64.getDecoder().decode(layoutBase64Image);
|
|
|
try (FileOutputStream fos = new FileOutputStream(layoutImagePath)) {
|
|
|
@@ -735,7 +765,7 @@ public class Main {
|
|
|
}
|
|
|
System.out.println("Output image saved at " + layoutImagePath);
|
|
|
|
|
|
- System.out.println("\nDetected seal impressions: " + impressions.toString());
|
|
|
+ System.out.println("\nDetected texts: " + texts.toString());
|
|
|
} else {
|
|
|
System.err.println("Request failed with code: " + response.code());
|
|
|
}
|
|
|
@@ -760,6 +790,7 @@ import (
|
|
|
func main() {
|
|
|
API_URL := "http://localhost:8080/seal-recognition"
|
|
|
imagePath := "./demo.jpg"
|
|
|
+ ocrImagePath := "./ocr.jpg"
|
|
|
layoutImagePath := "./layout.jpg"
|
|
|
|
|
|
imageBytes, err := ioutil.ReadFile(imagePath)
|
|
|
@@ -797,8 +828,9 @@ func main() {
|
|
|
}
|
|
|
type Response struct {
|
|
|
Result struct {
|
|
|
+ OcrImage string `json:"ocrImage"`
|
|
|
LayoutImage string `json:"layoutImage"`
|
|
|
- Impressions []map[string]interface{} `json:"sealImpressions"`
|
|
|
+ Texts []map[string]interface{} `json:"texts"`
|
|
|
} `json:"result"`
|
|
|
}
|
|
|
var respData Response
|
|
|
@@ -808,6 +840,18 @@ func main() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ ocrImageData, err := base64.StdEncoding.DecodeString(respData.Result.OcrImage)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error decoding base64 image data:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = ioutil.WriteFile(ocrImagePath, ocrImageData, 0644)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error writing image to file:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Printf("Image saved at %s.jpg\n", ocrImagePath)
|
|
|
+
|
|
|
layoutImageData, err := base64.StdEncoding.DecodeString(respData.Result.LayoutImage)
|
|
|
if err != nil {
|
|
|
fmt.Println("Error decoding base64 image data:", err)
|
|
|
@@ -820,9 +864,9 @@ func main() {
|
|
|
}
|
|
|
fmt.Printf("Image saved at %s.jpg\n", layoutImagePath)
|
|
|
|
|
|
- fmt.Println("\nDetected seal impressions:")
|
|
|
- for _, impression := range respData.Result.Impressions {
|
|
|
- fmt.Println(impression)
|
|
|
+ fmt.Println("\nDetected texts:")
|
|
|
+ for _, text := range respData.Result.Texts {
|
|
|
+ fmt.Println(text)
|
|
|
}
|
|
|
}
|
|
|
</code></pre></details>
|
|
|
@@ -841,6 +885,7 @@ class Program
|
|
|
{
|
|
|
static readonly string API_URL = "http://localhost:8080/seal-recognition";
|
|
|
static readonly string imagePath = "./demo.jpg";
|
|
|
+ static readonly string ocrImagePath = "./ocr.jpg";
|
|
|
static readonly string layoutImagePath = "./layout.jpg";
|
|
|
|
|
|
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["result"]["ocrImage"].ToString();
|
|
|
+ byte[] ocrImageBytes = Convert.FromBase64String(ocrBase64Image);
|
|
|
+ File.WriteAllBytes(ocrImagePath, ocrImageBytes);
|
|
|
+ Console.WriteLine($"Output image saved at {ocrImagePath}");
|
|
|
+
|
|
|
string layoutBase64Image = jsonResponse["result"]["layoutImage"].ToString();
|
|
|
byte[] layoutImageBytes = Convert.FromBase64String(layoutBase64Image);
|
|
|
File.WriteAllBytes(layoutImagePath, layoutImageBytes);
|
|
|
Console.WriteLine($"Output image saved at {layoutImagePath}");
|
|
|
|
|
|
- Console.WriteLine("\nDetected seal impressions:");
|
|
|
- Console.WriteLine(jsonResponse["result"]["sealImpressions"].ToString());
|
|
|
+ Console.WriteLine("\nDetected texts:");
|
|
|
+ Console.WriteLine(jsonResponse["result"]["texts"].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 = "./ocr.jpg";
|
|
|
const layoutImagePath = "./layout.jpg";
|
|
|
|
|
|
let config = {
|
|
|
@@ -897,14 +948,20 @@ axios.request(config)
|
|
|
.then((response) => {
|
|
|
const result = response.data["result"];
|
|
|
|
|
|
+ const imageBuffer = Buffer.from(result["ocrImage"], 'base64');
|
|
|
+ fs.writeFile(ocrImagePath, imageBuffer, (err) => {
|
|
|
+ if (err) throw err;
|
|
|
+ console.log(`Output image saved at ${ocrImagePath}`);
|
|
|
+ });
|
|
|
+
|
|
|
imageBuffer = Buffer.from(result["layoutImage"], 'base64');
|
|
|
fs.writeFile(layoutImagePath, imageBuffer, (err) => {
|
|
|
if (err) throw err;
|
|
|
console.log(`Output image saved at ${layoutImagePath}`);
|
|
|
});
|
|
|
|
|
|
- console.log("\nDetected seal impressions:");
|
|
|
- console.log(result["sealImpressions"]);
|
|
|
+ console.log("\nDetected texts:");
|
|
|
+ console.log(result["texts"]);
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
console.log(error);
|
|
|
@@ -917,6 +974,7 @@ axios.request(config)
|
|
|
|
|
|
$API_URL = "http://localhost:8080/seal-recognition";
|
|
|
$image_path = "./demo.jpg";
|
|
|
+$ocr_image_path = "./ocr.jpg";
|
|
|
$layout_image_path = "./layout.jpg";
|
|
|
|
|
|
$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)["result"];
|
|
|
+file_put_contents($ocr_image_path, base64_decode($result["ocrImage"]));
|
|
|
+echo "Output image saved at " . $ocr_image_path . "\n";
|
|
|
|
|
|
file_put_contents($layout_image_path, base64_decode($result["layoutImage"]));
|
|
|
echo "Output image saved at " . $layout_image_path . "\n";
|
|
|
|
|
|
-echo "\nDetected seal impressions:\n";
|
|
|
-print_r($result["sealImpressions"]);
|
|
|
+echo "\nDetected texts:\n";
|
|
|
+print_r($result["texts"]);
|
|
|
|
|
|
?>
|
|
|
</code></pre></details>
|