用到Tesseract开源项目来做文字简单的识别,查看所需要的函数的C++源码是这样的:
/** Returns an array of all word confidences, terminated by -1. */
int* TessBaseAPI::AllWordConfidences() {
if (tesseract_ == NULL ||
(!recognition_done_ && Recognize(NULL) < 0))
return NULL;
int n_word = 0;
PAGE_RES_IT res_it(page_res_);
for (res_it.restart_page(); res_it.word() != NULL; res_it.forward())
n_word++;
int* conf = new int[n_word+1];
n_word = 0;
for (res_it.restart_page(); res_it.word() != NULL; res_it.forward()) {
WERD_RES *word = res_it.word();
WERD_CHOICE* choice = word->best_choice;
int w_conf = static_cast<int>(100 + 5 * choice->certainty());
// This is the eq for converting Tesseract confidence to 1..100
if (w_conf < 0) w_conf = 0;
if (w_conf > 100) w_conf = 100;
conf[n_word++] = w_conf;
}
conf[n_word] = -1;
return conf;
}
而其java提供的接口函数是:
IntByReference TessBaseAPIAllWordConfidences(TessBaseAPI handle);
涉及到的JNA是com.sun.jna.ptr.IntByReference,现在需要获取IntByReference变量的所有值,使用getValue方法只能获取到一个数。求做过相关内容的帮忙指点一下啦!