为什么tessercat在flatmap函数中调用时返回错误?

gmxoilav  于 2021-06-21  发布在  Flink
关注(0)|答案(0)|浏览(317)

我需要使用tessearct库(tessearct library,tess4j)从bufferimage中提取文本,但是这个函数抛出一个nullpointerexception。我用的是flink 1.10
ps:当我在flatmap范围外执行函数getimagetext()时,该函数运行得非常好

public String getImgText(BufferedImage bufferImage) throws TesseractException {
       ITesseract instance = new Tesseract();
       try
       {
           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();
11:01:44,650 ERROR net.sourceforge.tess4j.Tesseract                              -
java.lang.NullPointerException
at sun.java2d.cmm.lcms.LCMS.getProfileSize(LCMS.java:67)
at java.awt.color.ICC_Profile.getData(ICC_Profile.java:1359)
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter.setupMetadata(TIFFImageWriter.java:1141)
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter.convertImageMetadata(TIFFImageWriter.java:433)
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter.getDefaultImageMetadata(TIFFImageWriter.java:350)
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:2565)
at com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:2383)
at net.sourceforge.tess4j.util.ImageIOHelper.getImageByteBuffer(ImageIOHelper.java:293)
at net.sourceforge.tess4j.Tesseract.setImage(Tesseract.java:398)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:291)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:264)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:245)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:229)
at OCR.TextExtraction.getImgText(TextExtraction.java:27)
at org.example.StreamingJob$2.flatMap(StreamingJob.java:59)
at org.example.StreamingJob$2.flatMap(StreamingJob.java:55)
at org.apache.flink.streaming.api.operators.StreamFlatMap.processElement(StreamFlatMap.java:50)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.pushToOperator(OperatorChain.java:641)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.collect(OperatorChain.java:616)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.collect(OperatorChain.java:596)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:730)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:708)
at org.apache.flink.streaming.api.operators.StreamSourceContexts$NonTimestampContext.collect(StreamSourceContexts.java:104)
at org.apache.flink.streaming.api.operators.StreamSourceContexts$NonTimestampContext.collectWithTimestamp(StreamSourceContexts.java:111)
at org.apache.flink.streaming.connectors.kafka.internals.AbstractFetcher.emitRecordWithTimestamp(AbstractFetcher.java:398)
at org.apache.flink.streaming.connectors.kafka.internal.KafkaFetcher.emitRecord(KafkaFetcher.java:185)
at org.apache.flink.streaming.connectors.kafka.internal.KafkaFetcher.runFetchLoop(KafkaFetcher.java:150)
at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase.run(FlinkKafkaConsumerBase.java:715)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:100)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:63)
at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:200)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题