package com.zzsn.test;

import com.zzsn.orc.BaiduOCR;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;

public class yztest {

    public static void main(String[] args) throws Exception {
        BufferedImage bufferedImage = ImageIO.read(new File("E:\\ideaWorkerspace\\sougou_search\\data\\11.png"));
        imageToBytes(bufferedImage);
        String ocrBady = BaiduOCR.imageBasicGeneralOcr(imageToBytes(bufferedImage));
        List<String> msgList = BaiduOCR.pasermsgJson(ocrBady);
        for (String msg:
             msgList) {
            System.out.println(msg);
        }
    }

    /**
     * BufferedImage转byte[]
     *
     * @param bImage BufferedImage对象
     * @return byte[]
     * @auth zhy
     */
    private static byte[] imageToBytes(BufferedImage bImage) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            ImageIO.write(bImage, "png", out);
        } catch (IOException e) {
            //log.error(e.getMessage());
        }
        return out.toByteArray();
    }
}
