Как определить текст с картинки с помощью javacpp tesseract?

BytePointer outText;

        TessBaseAPI api = new TessBaseAPI();
        // Initialize tesseract-ocr with English, without specifying tessdata path
        if (api.Init("C:/Users/Dom/GlobalWeather/", "eng") != 0) {
            System.err.println("Could not initialize tesseract.");
            System.exit(1);
        }

        File imgPath = new File("test.png");
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        BufferedImage img;

        try {
            img = ImageIO.read(imgPath);
            ImageIO.write(img, "png", baos );
        } catch (IOException e) {
            System.err.println("Reading file or writing byte[] failed.");
            e.printStackTrace();
        }

        byte[] imageInByte=baos.toByteArray();

        PIX image = pixReadMemPng(imageInByte, imageInByte.length);

        api.SetImage(image);
        // Get OCR result
        outText = api.GetUTF8Text();
        System.out.println("OCR output:\n" + outText.getString());

        // Destroy used object and release memory
        api.End();
        outText.deallocate();
        pixDestroy(image);


вот мой код, когда я его запускаю то image = null? почему так получается?
  • Вопрос задан
  • 549 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы