zhongrj
2024-03-19 c9b71ca2cd9a71a7b9f2e5669f60bfaece4ad67b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.springblade.modules.test4j;
 
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import net.sourceforge.tess4j.Tesseract;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import javax.imageio.ImageIO;
 
@RestController
@AllArgsConstructor
@RequestMapping("/test4j")
@Api(value = "图片智能识别", tags = "图片智能识别")
public class Test4jController {
 
    @PostMapping("/read-id")
    public R readText(@RequestParam("file") MultipartFile file) {
        // 在这里添加识别文本的代码,例如Tesseract OCR
        Tesseract tesseract = new Tesseract();
        // 设置Tesseract的路径
        tesseract.setDatapath("F:\\test4jdata");
        // 设置为中文简体
        tesseract.setLanguage("chi_sim");
        try {
            String text = tesseract.doOCR(ImageIO.read(file.getInputStream()));
            return R.data(text);
        } catch (Exception e) {
            return R.data(e.getMessage());
        }
    }
}