u
This commit is contained in:
1 parent
9d7bf97823
commit
7c64e29ffb
16 files changed
+784
-35
No files matched your search
Generated
+2
@@ -15,6 +15,8 @@
|
||||
<file url="file://$PROJECT_DIR$/crane-doc/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-log/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-log/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-test/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-test/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-web/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/crane-web/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.crane</groupId>
|
||||
<artifactId>crane-common</artifactId>
|
||||
<artifactId>crane-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.crane.boot;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = {"com.crane"})
|
||||
public class CraneBootApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CraneBootApplication.class, args);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
server:
|
||||
port: 8080
|
||||
port: 8082
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
logging:
|
||||
module-name: 启动模块
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
logging:
|
||||
module-name: common模块
|
||||
@@ -10,11 +10,6 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>crane-log</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<description>日志模块</description>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.crane</groupId>
|
||||
<artifactId>crane-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>crane-test</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.crane</groupId>
|
||||
<artifactId>crane-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.crane</groupId>
|
||||
<artifactId>crane-log</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.crane.common;
|
||||
package com.crane.test;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.crane.test;
|
||||
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 Test{
|
||||
public static void main(String[] args) throws IOException {
|
||||
String API_URL = "http://localhost:8080/ocr";
|
||||
String imagePath = "./demo.jpg";
|
||||
|
||||
File file = new File(imagePath);
|
||||
byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
|
||||
String base64Image = Base64.getEncoder().encodeToString(fileContent);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode payload = objectMapper.createObjectNode();
|
||||
payload.put("file", base64Image);
|
||||
payload.put("fileType", 1);
|
||||
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
||||
RequestBody body = RequestBody.create(JSON, payload.toString());
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(API_URL)
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (response.isSuccessful()) {
|
||||
String responseBody = response.body().string();
|
||||
JsonNode root = objectMapper.readTree(responseBody);
|
||||
JsonNode result = root.get("result");
|
||||
|
||||
JsonNode ocrResults = result.get("ocrResults");
|
||||
for (int i = 0; i < ocrResults.size(); i++) {
|
||||
JsonNode item = ocrResults.get(i);
|
||||
|
||||
JsonNode prunedResult = item.get("prunedResult");
|
||||
System.out.println("Pruned Result [" + i + "]: " + prunedResult.toString());
|
||||
|
||||
String ocrImageBase64 = item.get("ocrImage").asText();
|
||||
byte[] ocrImageBytes = Base64.getDecoder().decode(ocrImageBase64);
|
||||
String ocrImgPath = "ocr_result_" + i + ".jpg";
|
||||
try (FileOutputStream fos = new FileOutputStream(ocrImgPath)) {
|
||||
fos.write(ocrImageBytes);
|
||||
System.out.println("Saved OCR image to: " + ocrImgPath);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Request failed with HTTP code: " + response.code());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
logging:
|
||||
module-name: 测试模块
|
||||
@@ -16,6 +16,7 @@
|
||||
<module>crane-common</module>
|
||||
<module>crane-boot</module>
|
||||
<module>crane-log</module>
|
||||
<module>crane-test</module>
|
||||
</modules>
|
||||
|
||||
<!-- 版本信息 -->
|
||||
@@ -80,6 +81,12 @@
|
||||
<artifactId>crane-log</artifactId>
|
||||
<version>${crane.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.crane</groupId>
|
||||
<artifactId>crane-test</artifactId>
|
||||
<version>${crane.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in new issue
Block a user