|
@@ -543,6 +543,8 @@ paddlex --pipeline OCR \
|
|
|
--device gpu:0
|
|
--device gpu:0
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
|
|
|
|
+
|
|
|
For details on the relevant parameter descriptions, please refer to the parameter descriptions in [2.2.2 Python Script Integration](#222-python-script-integration). Supports specifying multiple devices simultaneously for parallel inference. For details, please refer to the documentation on pipeline parallel inference.
|
|
For details on the relevant parameter descriptions, please refer to the parameter descriptions in [2.2.2 Python Script Integration](#222-python-script-integration). Supports specifying multiple devices simultaneously for parallel inference. For details, please refer to the documentation on pipeline parallel inference.
|
|
|
|
|
|
|
|
After running, the results will be printed to the terminal as follows:
|
|
After running, the results will be printed to the terminal as follows:
|
|
@@ -1207,8 +1209,8 @@ for i, res in enumerate(result["ocrResults"]):
|
|
|
#include "base64.hpp" // https://github.com/tobiaslocker/base64
|
|
#include "base64.hpp" // https://github.com/tobiaslocker/base64
|
|
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
|
- httplib::Client client("localhost", 8080);
|
|
|
|
|
- const std::string filePath = "./demo.jpg";
|
|
|
|
|
|
|
+ httplib::Client client("localhost", 8080);
|
|
|
|
|
+ const std::string filePath = "./demo.jpg";
|
|
|
|
|
|
|
|
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
|
|
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
|
|
|
if (!file) {
|
|
if (!file) {
|
|
@@ -1231,7 +1233,7 @@ int main() {
|
|
|
|
|
|
|
|
nlohmann::json jsonObj;
|
|
nlohmann::json jsonObj;
|
|
|
jsonObj["file"] = encodedFile;
|
|
jsonObj["file"] = encodedFile;
|
|
|
- jsonObj["fileType"] = 1;
|
|
|
|
|
|
|
+ jsonObj["fileType"] = 1;
|
|
|
|
|
|
|
|
auto response = client.Post("/ocr", jsonObj.dump(), "application/json");
|
|
auto response = client.Post("/ocr", jsonObj.dump(), "application/json");
|
|
|
|
|
|
|
@@ -1288,8 +1290,8 @@ import java.util.Base64;
|
|
|
|
|
|
|
|
public class Main {
|
|
public class Main {
|
|
|
public static void main(String[] args) throws IOException {
|
|
public static void main(String[] args) throws IOException {
|
|
|
- String API_URL = "http://localhost:8080/ocr";
|
|
|
|
|
- String imagePath = "./demo.jpg";
|
|
|
|
|
|
|
+ String API_URL = "http://localhost:8080/ocr";
|
|
|
|
|
+ String imagePath = "./demo.jpg";
|
|
|
|
|
|
|
|
File file = new File(imagePath);
|
|
File file = new File(imagePath);
|
|
|
byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
|
|
byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
|
|
@@ -1297,12 +1299,12 @@ public class Main {
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
ObjectNode payload = objectMapper.createObjectNode();
|
|
ObjectNode payload = objectMapper.createObjectNode();
|
|
|
- payload.put("file", base64Image);
|
|
|
|
|
- payload.put("fileType", 1);
|
|
|
|
|
|
|
+ payload.put("file", base64Image);
|
|
|
|
|
+ payload.put("fileType", 1);
|
|
|
|
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
|
MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
|
|
- RequestBody body = RequestBody.create(JSON, payload.toString());
|
|
|
|
|
|
|
+ RequestBody body = RequestBody.create(JSON, payload.toString());
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.url(API_URL)
|
|
.url(API_URL)
|
|
@@ -1399,14 +1401,14 @@ func main() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type OcrResult struct {
|
|
type OcrResult struct {
|
|
|
- PrunedResult map[string]interface{} `json:"prunedResult"`
|
|
|
|
|
- OcrImage *string `json:"ocrImage"`
|
|
|
|
|
|
|
+ PrunedResult map[string]interface{} `json:"prunedResult"`
|
|
|
|
|
+ OcrImage *string `json:"ocrImage"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type Response struct {
|
|
type Response struct {
|
|
|
Result struct {
|
|
Result struct {
|
|
|
OcrResults []OcrResult `json:"ocrResults"`
|
|
OcrResults []OcrResult `json:"ocrResults"`
|
|
|
- DataInfo interface{} `json:"dataInfo"`
|
|
|
|
|
|
|
+ DataInfo interface{} `json:"dataInfo"`
|
|
|
} `json:"result"`
|
|
} `json:"result"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1417,14 +1419,14 @@ func main() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i, res := range respData.Result.OcrResults {
|
|
for i, res := range respData.Result.OcrResults {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if res.OcrImage != nil {
|
|
if res.OcrImage != nil {
|
|
|
imgBytes, err := base64.StdEncoding.DecodeString(*res.OcrImage)
|
|
imgBytes, err := base64.StdEncoding.DecodeString(*res.OcrImage)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
fmt.Printf("Error decoding image %d: %v\n", i, err)
|
|
fmt.Printf("Error decoding image %d: %v\n", i, err)
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
filename := fmt.Sprintf("ocr_%d.jpg", i)
|
|
filename := fmt.Sprintf("ocr_%d.jpg", i)
|
|
|
if err := ioutil.WriteFile(filename, imgBytes, 0644); err != nil {
|
|
if err := ioutil.WriteFile(filename, imgBytes, 0644); err != nil {
|
|
|
fmt.Printf("Error saving image %s: %v\n", filename, err)
|
|
fmt.Printf("Error saving image %s: %v\n", filename, err)
|
|
@@ -1500,8 +1502,8 @@ const fs = require('fs');
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const API_URL = 'http://localhost:8080/layout-parsing';
|
|
const API_URL = 'http://localhost:8080/layout-parsing';
|
|
|
-const imagePath = './demo.jpg';
|
|
|
|
|
-const fileType = 1;
|
|
|
|
|
|
|
+const imagePath = './demo.jpg';
|
|
|
|
|
+const fileType = 1;
|
|
|
|
|
|
|
|
function encodeImageToBase64(filePath) {
|
|
function encodeImageToBase64(filePath) {
|
|
|
const bitmap = fs.readFileSync(filePath);
|
|
const bitmap = fs.readFileSync(filePath);
|
|
@@ -1541,13 +1543,13 @@ axios.post(API_URL, payload)
|
|
|
|
|
|
|
|
<pre><code class="language-php"><?php
|
|
<pre><code class="language-php"><?php
|
|
|
|
|
|
|
|
-$API_URL = "http://localhost:8080/ocr";
|
|
|
|
|
-$image_path = "./demo.jpg";
|
|
|
|
|
|
|
+$API_URL = "http://localhost:8080/ocr";
|
|
|
|
|
+$image_path = "./demo.jpg";
|
|
|
|
|
|
|
|
$image_data = base64_encode(file_get_contents($image_path));
|
|
$image_data = base64_encode(file_get_contents($image_path));
|
|
|
$payload = array(
|
|
$payload = array(
|
|
|
"file" => $image_data,
|
|
"file" => $image_data,
|
|
|
- "fileType" => 1
|
|
|
|
|
|
|
+ "fileType" => 1
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$ch = curl_init($API_URL);
|
|
$ch = curl_init($API_URL);
|