在JavaCpp Tessearact中获取单词级边界框

时间:2016-08-11 15:41:24

标签: java ocr tesseract bounding-box javacpp

我试图从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);
    }
}

0 个答案:

没有答案