| 123456789101112131415161718192021222324252627282930313233343536 |
- package com.jeesite.modules.mes.service;
- import lombok.AllArgsConstructor;
- import net.sourceforge.tess4j.Tesseract;
- import net.sourceforge.tess4j.TesseractException;
- import org.springframework.stereotype.Service;
- import org.springframework.web.multipart.MultipartFile;
- import javax.imageio.ImageIO;
- import java.awt.image.BufferedImage;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- @Service
- @AllArgsConstructor
- public class OcrService {
- private final Tesseract tesseract;
- /*
- * 识别图片中的数据
- * @param imageFile 图片文件
- * @ return 识别信息
- * */
- public String recognizeText(MultipartFile imageFile) throws TesseractException, IOException {
- // 转换
- InputStream sbs = new ByteArrayInputStream(imageFile.getBytes());
- BufferedImage bufferedImage = ImageIO.read(sbs);
- return tesseract.doOCR(bufferedImage);
- }
- }
|