2

我正在尝试从 javacpp tesseract 中提取每个单词的边界框。这似乎是边界框调用(下面是我的完整代码):

boolean box = ri.BoundingBox(RIL_WORD, coord1, coord2, coord3, coord4)

RIL_WORD 是可以针对单词、句子和段落进行调整的迭代器级别。坐标是 IntPointers(包含在 javacpp 中的类)。

api 说这会返回边界框坐标,但会返回一个布尔值。所以此时我知道有一个边界框,但仍然无法获得实际坐标。有谁知道如何从 java cpp tessaract 中获取边界框矩形?谢谢您的帮助。我已经发布了我的工作代码,用于获取下面的单个单词和置信度,因为我很难找到示例。

public class TesseractOCR {
    public void OCRText() {
        BytePointer outText;

        TessBaseAPI api = new TessBaseAPI();
        // Initialize tesseract-ocr with English, without specifying tessdata path

    if (api.Init(null, "eng") != 0) {
        System.err.println("Could not initialize tesseract.");
        System.exit(1);
    }

    // Open input image with leptonica library

    org.bytedeco.javacpp.lept.PIX image = pixRead("testimage.png");


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


    final ResultIterator ri = api.GetIterator();

    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    IntPointer coord1 = new IntPointer(x1);
    IntPointer coord2 = new IntPointer(y1);
    IntPointer coord3 = new IntPointer(x2);
    IntPointer coord4 = new IntPointer(y2);

    ri.Begin();

    if (ri !=null) {

        do {
            BytePointer word = ri.GetUTF8Text(RIL_WORD);
            float conf  = ri.Confidence(RIL_WORD);
            boolean box = ri.BoundingBox(RIL_WORD, coord1, coord2, coord3, coord4);

            System.out.println(word.getString());
            System.out.println(conf);
            System.out.println(box);


        } while (ri.Next(RIL_WORD));

    }



    api.End();
    outText.deallocate();
    pixDestroy(image);
    }
}
4

0 回答 0