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());
|
}
|
}
|
}
|