问题描述
我需要使用tessearct库(tess4j)从bufferImage中提取文本,但是函数会抛出NullPointerException。
PS:当我在flatMap范围之外执行函数getImageText()
时,该函数运行正常
public String getImgText(BufferedImage bufferImage) throws TesseractException {
ITesseract instance = new Tesseract();
try
{
if (instance == null){
System.out.println("instance is null");
}
String imgText = instance.doOCR(bufferImage);
return imgText;
}
catch (TesseractException e)
{
return "Error while reading image: "+e.getMessage();
}
}
e_stream.flatMap(new FlatMapFunction<BufferedImage,String>() {
@Override
public void flatMap(BufferedImage iBuffer,Collector<String> out) throws Exception{
TextExtraction ocr = new TextExtraction();
String cv = ocr.getImgText(iBuffer);
out.collect(cv);
}
}).print();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)