|
|
@@ -252,40 +252,40 @@ Below are the API reference and multi-language service invocation examples:
|
|
|
|
|
|
<p>For all operations provided by the service:</p>
|
|
|
<ul>
|
|
|
-<li>The response body and the request body of POST requests are both JSON data (JSON objects).</li>
|
|
|
-<li>When the request is successfully processed, the response status code is <code>200</code>, and the attributes of the response body are as follows:</li>
|
|
|
+<li>Both the response body and the request body for POST requests are JSON data (JSON objects).</li>
|
|
|
+<li>When the request is processed successfully, the response status code is <code>200</code>, and the response body properties are as follows:</li>
|
|
|
</ul>
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>Name</th>
|
|
|
<th>Type</th>
|
|
|
-<th>Meaning</th>
|
|
|
+<th>Description</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<td><code>errorCode</code></td>
|
|
|
<td><code>integer</code></td>
|
|
|
-<td>Error code. Fixed to <code>0</code>.</td>
|
|
|
+<td>Error code. Fixed as <code>0</code>.</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td><code>errorMsg</code></td>
|
|
|
<td><code>string</code></td>
|
|
|
-<td>Error description. Fixed to <code>"Success"</code>.</td>
|
|
|
+<td>Error description. Fixed as <code>"Success"</code>.</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
-<p>The response body may also have a <code>result</code> attribute of type <code>object</code>, which stores the operation result information.</p>
|
|
|
+<p>The response body may also have a <code>result</code> property of type <code>object</code>, which stores the operation result information.</p>
|
|
|
<ul>
|
|
|
-<li>When the request is not successfully processed, the attributes of the response body are as follows:</li>
|
|
|
+<li>When the request is not processed successfully, the response body properties are as follows:</li>
|
|
|
</ul>
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>Name</th>
|
|
|
<th>Type</th>
|
|
|
-<th>Meaning</th>
|
|
|
+<th>Description</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
@@ -301,21 +301,21 @@ Below are the API reference and multi-language service invocation examples:
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
-<p>The operations provided by the service are as follows:</p>
|
|
|
+<p>Operations provided by the service are as follows:</p>
|
|
|
<ul>
|
|
|
<li><b><code>infer</code></b></li>
|
|
|
</ul>
|
|
|
-<p>Obtain OCR results for an image.</p>
|
|
|
-<p><code>POST /ocr</code></p>
|
|
|
+<p>Get pedestrian attribute recognition results.</p>
|
|
|
+<p><code>POST /pedestrian-attribute-recognition</code></p>
|
|
|
<ul>
|
|
|
-<li>The attributes of the request body are as follows:</li>
|
|
|
+<li>The request body properties are as follows:</li>
|
|
|
</ul>
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>Name</th>
|
|
|
<th>Type</th>
|
|
|
-<th>Meaning</th>
|
|
|
+<th>Description</th>
|
|
|
<th>Required</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
@@ -323,18 +323,88 @@ Below are the API reference and multi-language service invocation examples:
|
|
|
<tr>
|
|
|
<td><code>image</code></td>
|
|
|
<td><code>string</code></td>
|
|
|
-<td>The URL of an accessible image file or the Base64 encoded result of the image file content.</td>
|
|
|
+<td>The URL of an image file accessible by the service or the Base64 encoded result of the image file content.</td>
|
|
|
<td>Yes</td>
|
|
|
</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li>When the request is processed successfully, the <code>result</code> of the response body has the following properties:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>Name</th>
|
|
|
+<th>Type</th>
|
|
|
+<th>Description</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>pedestrians</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>Information about the pedestrian's location and attributes.</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>image</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>The pedestrian attribute recognition result image. The image is in JPEG format and encoded using Base64.</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p>Each element in <code>pedestrians</code> is an <code>object</code> with the following properties:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>Name</th>
|
|
|
+<th>Type</th>
|
|
|
+<th>Description</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>bbox</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>The location of the pedestrian. The elements in the array are the x-coordinate of the top-left corner, the y-coordinate of the top-left corner, the x-coordinate of the bottom-right corner, and the y-coordinate of the bottom-right corner of the bounding box, respectively.</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>attributes</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>The pedestrian attributes.</td>
|
|
|
+</tr>
|
|
|
<tr>
|
|
|
-<td><code>inferenceParams</code></td>
|
|
|
-<td><code>object</code></td>
|
|
|
-<td>Inference parameters.</td>
|
|
|
-<td>No</td>
|
|
|
+<td><code>score</code></td>
|
|
|
+<td><code>number</code></td>
|
|
|
+<td>The detection score.</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
-<p>The attributes of```markdown</p>
|
|
|
+<p>Each element in <code>attributes</code> is an <code>object</code> with the following properties:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>Name</th>
|
|
|
+<th>Type</th>
|
|
|
+<th>Description</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>label</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>The label of the attribute.</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>score</code></td>
|
|
|
+<td><code>number</code></td>
|
|
|
+<td>The classification score.</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>Multi-Language Service Invocation Examples</summary>
|
|
|
+
|
|
|
<details>
|
|
|
<summary>Python</summary>
|
|
|
|
|
|
@@ -342,337 +412,27 @@ Below are the API reference and multi-language service invocation examples:
|
|
|
<pre><code class="language-python">import base64
|
|
|
import requests
|
|
|
|
|
|
-API_URL = "http://localhost:8080/ocr" # Service URL
|
|
|
+API_URL = "http://localhost:8080/pedestrian-attribute-recognition"
|
|
|
image_path = "./demo.jpg"
|
|
|
output_image_path = "./out.jpg"
|
|
|
|
|
|
-# Encode the local image to Base64
|
|
|
with open(image_path, "rb") as file:
|
|
|
image_bytes = file.read()
|
|
|
image_data = base64.b64encode(image_bytes).decode("ascii")
|
|
|
|
|
|
-payload = {"image": image_data} # Base64 encoded file content or image URL
|
|
|
+payload = {"image": image_data}
|
|
|
|
|
|
-# Call the API
|
|
|
response = requests.post(API_URL, json=payload)
|
|
|
|
|
|
-# Process the response data
|
|
|
assert response.status_code == 200
|
|
|
result = response.json()["result"]
|
|
|
with open(output_image_path, "wb") as file:
|
|
|
file.write(base64.b64decode(result["image"]))
|
|
|
print(f"Output image saved at {output_image_path}")
|
|
|
-print("\nDetected texts:")
|
|
|
-print(result["texts"])
|
|
|
+print("\nDetected pedestrians:")
|
|
|
+print(result["pedestrians"])
|
|
|
</code></pre></details>
|
|
|
-
|
|
|
-<details><summary>C++</summary>
|
|
|
-
|
|
|
-<pre><code class="language-cpp">#include <iostream>
|
|
|
-#include "cpp-httplib/httplib.h" // https://github.com/Huiyicc/cpp-httplib
|
|
|
-#include "nlohmann/json.hpp" // https://github.com/nlohmann/json
|
|
|
-#include "base64.hpp" // https://github.com/tobiaslocker/base64
|
|
|
-
|
|
|
-int main() {
|
|
|
- httplib::Client client("localhost:8080");
|
|
|
- const std::string imagePath = "./demo.jpg";
|
|
|
- const std::string outputImagePath = "./out.jpg";
|
|
|
-
|
|
|
- httplib::Headers headers = {
|
|
|
- {"Content-Type", "application/json"}
|
|
|
- };
|
|
|
-
|
|
|
- // Encode the local image to Base64
|
|
|
- std::ifstream file(imagePath, std::ios::binary | std::ios::ate);
|
|
|
- std::streamsize size = file.tellg();
|
|
|
- file.seekg(0, std::ios::beg);
|
|
|
-
|
|
|
- std::vector<char> buffer(size);
|
|
|
- if (!file.read(buffer.data(), size)) {
|
|
|
- std::cerr << "Error reading file." << std::endl;
|
|
|
- return 1;
|
|
|
- }
|
|
|
- std::string bufferStr(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
|
|
- std::string encodedImage = base64::to_base64(bufferStr);
|
|
|
-
|
|
|
- nlohmann::json jsonObj;
|
|
|
- jsonObj["image"] = encodedImage;
|
|
|
- std::string body = jsonObj.dump();
|
|
|
-
|
|
|
- // Call the API
|
|
|
- auto response = client.Post("/ocr", headers, body, "application/json");
|
|
|
- // Process the response data
|
|
|
- if (response && response->status == 200) {
|
|
|
- nlohmann::json jsonResponse = nlohmann::json::parse(response->body);
|
|
|
- auto result = jsonResponse["result"];
|
|
|
-
|
|
|
- encodedImage = result["image"];
|
|
|
- std::string decodedString = base64::from_base64(encodedImage);
|
|
|
- std::vector<unsigned char> decodedImage(decodedString.begin(), decodedString.end());
|
|
|
- std::ofstream outputImage(outputImagePath, std::ios::binary | std::ios::out);
|
|
|
- if (outputImage.is_open()) {
|
|
|
- outputImage.write(reinterpret_cast<char*>(decodedImage.data()), decodedImage.size());
|
|
|
- outputImage.close();
|
|
|
- std::cout << "Output image saved at " << outputImagePath << std::endl;
|
|
|
- } else {
|
|
|
- std::cerr << "Unable to open file for writing: " << outputImagePath << 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;
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-</code></pre></details>
|
|
|
-``````markdown
|
|
|
-# Tutorial on Artificial Intelligence and Computer Vision
|
|
|
-
|
|
|
-This tutorial, intended for numerous developers, covers the basics and applications of AI and Computer Vision.
|
|
|
-
|
|
|
-<details><summary>Java</summary>
|
|
|
-
|
|
|
-<pre><code class="language-java">import okhttp3.*;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
-import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Base64;
|
|
|
-
|
|
|
-public class Main {
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
- String API_URL = "http://localhost:8080/ocr"; // Service URL
|
|
|
- String imagePath = "./demo.jpg"; // Local image path
|
|
|
- String outputImagePath = "./out.jpg"; // Output image path
|
|
|
-
|
|
|
- // Encode the local image to Base64
|
|
|
- File file = new File(imagePath);
|
|
|
- byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
|
|
|
- String imageData = Base64.getEncoder().encodeToString(fileContent);
|
|
|
-
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- ObjectNode params = objectMapper.createObjectNode();
|
|
|
- params.put("image", imageData); // Base64-encoded file content or image URL
|
|
|
-
|
|
|
- // Create an OkHttpClient instance
|
|
|
- OkHttpClient client = new OkHttpClient();
|
|
|
- MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
|
|
- RequestBody body = RequestBody.create(params.toString(), JSON);
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(API_URL)
|
|
|
- .post(body)
|
|
|
- .build();
|
|
|
-
|
|
|
- // Call the API and process the response
|
|
|
- try (Response response = client.newCall(request).execute()) {
|
|
|
- if (response.isSuccessful()) {
|
|
|
- String responseBody = response.body().string();
|
|
|
- JsonNode resultNode = objectMapper.readTree(responseBody);
|
|
|
- JsonNode result = resultNode.get("result");
|
|
|
- String base64Image = result.get("image").asText();
|
|
|
- JsonNode texts = result.get("texts");
|
|
|
-
|
|
|
- byte[] imageBytes = Base64.getDecoder().decode(base64Image);
|
|
|
- try (FileOutputStream fos = new FileOutputStream(outputImagePath)) {
|
|
|
- fos.write(imageBytes);
|
|
|
- }
|
|
|
- System.out.println("Output image saved at " + outputImagePath);
|
|
|
- System.out.println("\nDetected texts: " + texts.toString());
|
|
|
- } else {
|
|
|
- System.err.println("Request failed with code: " + response.code());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-</code></pre></details>
|
|
|
-
|
|
|
-<details><summary>Go</summary>
|
|
|
-
|
|
|
-<pre><code class="language-go">package main
|
|
|
-
|
|
|
-import (
|
|
|
- "bytes"
|
|
|
- "encoding/base64"
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "io/ioutil"
|
|
|
- "net/http"
|
|
|
-)
|
|
|
-
|
|
|
-func main() {
|
|
|
- API_URL := "http://localhost:8080/ocr"
|
|
|
- imagePath := "./demo.jpg"
|
|
|
- outputImagePath := "./out.jpg"
|
|
|
-
|
|
|
- // Encode the local image to Base64
|
|
|
- imageBytes, err := ioutil.ReadFile(imagePath)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error reading image file:", err)
|
|
|
- return
|
|
|
- }
|
|
|
- imageData := base64.StdEncoding.EncodeToString(imageBytes)
|
|
|
-
|
|
|
- payload := map[string]string{"image": imageData} // Base64-encoded file content or image URL
|
|
|
- payloadBytes, err := json.Marshal(payload)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error marshaling payload:", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // Call the API
|
|
|
- client := &http.Client{}
|
|
|
- req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes))
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error creating request:", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- res, err := client.Do(req)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error sending request:", err)
|
|
|
- return
|
|
|
- }
|
|
|
- defer res.Body.Close()
|
|
|
-
|
|
|
- // Process the response
|
|
|
- body, err := ioutil.ReadAll(res.Body)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error reading response body:", err)
|
|
|
- return
|
|
|
- }```markdown
|
|
|
-# An English Tutorial on Artificial Intelligence and Computer Vision
|
|
|
-
|
|
|
-This tutorial document is intended for numerous developers and covers content related to artificial intelligence and computer vision.
|
|
|
-
|
|
|
-<details>
|
|
|
-<summary>C#</summary>
|
|
|
-
|
|
|
-```csharp
|
|
|
-using System;
|
|
|
-using System.IO;
|
|
|
-using System.Net.Http;
|
|
|
-using System.Net.Http.Headers;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using Newtonsoft.Json.Linq;
|
|
|
-
|
|
|
-class Program
|
|
|
-{
|
|
|
-static readonly string API_URL = "http://localhost:8080/ocr";
|
|
|
-static readonly string imagePath = "./demo.jpg";
|
|
|
-static readonly string outputImagePath = "./out.jpg";
|
|
|
-
|
|
|
-static async Task Main(string[] args)
|
|
|
-{
|
|
|
-var httpClient = new HttpClient();
|
|
|
-
|
|
|
-// Encode the local image to Base64
|
|
|
-byte[] imageBytes = File.ReadAllBytes(imagePath);
|
|
|
-string image_data = Convert.ToBase64String(imageBytes);
|
|
|
-
|
|
|
-var payload = new JObject{ { "image", image_data } }; // Base64 encoded file content or image URL
|
|
|
-var content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json");
|
|
|
-
|
|
|
-// Call the API
|
|
|
-HttpResponseMessage response = await httpClient.PostAsync(API_URL, content);
|
|
|
-response.EnsureSuccessStatusCode();
|
|
|
-
|
|
|
-// Process the API response
|
|
|
-string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
-JObject jsonResponse = JObject.Parse(responseBody);
|
|
|
-
|
|
|
-string base64Image = jsonResponse["result"]["image"].ToString();
|
|
|
-byte[] outputImageBytes = Convert.FromBase64String(base64Image);
|
|
|
-
|
|
|
-File.WriteAllBytes(outputImagePath, outputImageBytes);
|
|
|
-Console.WriteLine($"Output image saved at {outputImagePath}");
|
|
|
-Console.WriteLine("\nDetected texts:");
|
|
|
-Console.WriteLine(jsonResponse["result"]["texts"].ToString());
|
|
|
-}
|
|
|
-}
|
|
|
-</code></pre></details>
|
|
|
-
|
|
|
-<details><summary>Node.js</summary>
|
|
|
-
|
|
|
-<pre><code class="language-js">const axios = require('axios');
|
|
|
-const fs = require('fs');
|
|
|
-
|
|
|
-const API_URL = 'http://localhost:8080/ocr';
|
|
|
-const imagePath = './demo.jpg';
|
|
|
-const outputImagePath = "./out.jpg";
|
|
|
-
|
|
|
-let config = {
|
|
|
- method: 'POST',
|
|
|
- maxBodyLength: Infinity,
|
|
|
- url: API_URL,
|
|
|
- data: JSON.stringify({
|
|
|
- 'image': encodeImageToBase64(imagePath) // Base64 encoded file content or image URL
|
|
|
- })
|
|
|
-};
|
|
|
-
|
|
|
-// Encode the local image to Base64
|
|
|
-function encodeImageToBase64(filePath) {
|
|
|
- const bitmap = fs.readFileSync(filePath);
|
|
|
- return Buffer.from(bitmap).toString('base64');
|
|
|
-}
|
|
|
-
|
|
|
-// Call the API
|
|
|
-axios.request(config)
|
|
|
-.then((response) => {
|
|
|
- // Process the API response
|
|
|
- const result = response.data["result"];
|
|
|
- const imageBuffer = Buffer.from(result["image"], 'base64');
|
|
|
- fs.writeFile(outputImagePath, imageBuffer, (err) => {
|
|
|
- if (err) throw err;
|
|
|
- console.log(`Output image saved at ${outputImagePath}`);
|
|
|
- });
|
|
|
- console.log("\nDetected texts:");
|
|
|
- console.log(result["texts"]);
|
|
|
-})
|
|
|
-.catch((error) => {
|
|
|
- console.log(error);
|
|
|
-});
|
|
|
-</code></pre></details>
|
|
|
-
|
|
|
-<details>
|
|
|
-<summary>PHP</summary>
|
|
|
-
|
|
|
-```php
|
|
|
-<?php
|
|
|
-
|
|
|
-$API_URL = "http://localhost:8080/ocr"; // Service URL
|
|
|
-$image_path = "./demo.jpg";
|
|
|
-$output_image_path = "./out.jpg";
|
|
|
-
|
|
|
-// Encode the local image to Base64
|
|
|
-$image_data = base64_encode(file_get_contents($image_path));
|
|
|
-$payload = array("image" => $image_data); // Base64 encoded file content or image URL
|
|
|
-
|
|
|
-// Call the API
|
|
|
-$ch = curl_init($API_URL);
|
|
|
-curl_setopt($ch, CURLOPT_POST, true);
|
|
|
-curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
|
|
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
-$response = curl_exec($ch);
|
|
|
-curl_close($ch);
|
|
|
-
|
|
|
-// Process the API response
|
|
|
-$result = json_decode($response, true)["result"];
|
|
|
-file_put_contents($output
|
|
|
-```
|
|
|
-
|
|
|
-<details>
|
|
|
-<details>
|
|
|
+</details>
|
|
|
<br/>
|
|
|
|
|
|
📱 <b>Edge Deployment</b>: Edge deployment is a method where computing and data processing functions are placed on the user's device itself, allowing the device to process data directly without relying on remote servers. PaddleX supports deploying models on edge devices such as Android. For detailed edge deployment procedures, please refer to the [PaddleX Edge Deployment Guide](../../../pipeline_deploy/edge_deploy.en.md).
|