gpt4 book ai didi

java - 有没有办法在 UI (JavaFX) 中显示 tess4j 进度?

转载 作者:行者123 更新时间:2023-12-01 09:22:13 28 4
gpt4 key购买 nike

我需要在 Javafx UI 中显示 tess4j(OCR 库)进度。

public void testOCR() {
File file = new File("test.png");
ITesseract instance = new Tesseract();

try {
String s = instance.doOCR(file);
instance.setLanguage("fas");
System.out.println(s);

} catch (TesseractException e) {
System.out.println(e.getMessage());
}
}

最佳答案

您可能对 tess4J 存储库中的 ProgressMonitor 代码感兴趣。我认为它与您正在寻找的内容类似。

package net.sourceforge.tess4j;

import com.sun.jna.Pointer;
import net.sourceforge.tess4j.util.LoggHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static net.sourceforge.tess4j.ITessAPI.TRUE;

class ProgressMonitor extends Thread {

ITessAPI.ETEXT_DESC monitor;
StringBuilder outputMessage = new StringBuilder();

private static final Logger logger = LoggerFactory.getLogger(new LoggHelper().toString());

public ProgressMonitor(ITessAPI.ETEXT_DESC monitor) {
this.monitor = monitor;
}

public String getMessage() {
return outputMessage.toString();
}

@Override
public void run() {
try {
while (true) {
logger.info("ocr alive: " + (monitor.ocr_alive == TRUE));
logger.info("progress: " + monitor.progress);
outputMessage.append(monitor.more_to_come);
if (monitor.progress >= 100) {
break;
}
Thread.sleep(100);
}
} catch (Exception ioe) {
ioe.printStackTrace();
}
}

/**
* Cancels OCR operation.
*/
public void cancel() {
monitor.cancel = new ITessAPI.CANCEL_FUNC() {
@Override
public boolean invoke(Pointer cancel_this, int words) {
return true;
}
};
}

/**
* Resets cancel flag.
*/
public void reset() {
monitor.cancel = null;
}

}

关于java - 有没有办法在 UI (JavaFX) 中显示 tess4j 进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40099921/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com