mapper不发出任何东西

dffbzjpn  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(174)

我有一个mapreduce作业,它接受我以前构造的序列文件。序列文件的键是图像文件名,值是图像的字节表示。我的Map器应该获取每个图像,然后使用一个名为tesseract的图像到文本库对它们进行处理,该库基于tesseract。Map程序运行并且不会抛出任何异常,但令人惊讶的是输出文件夹是空的,并且没有生成任何文件。这是我的Map程序代码:

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import net.sourceforge.tess4j.*;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.hadoop.io.ByteWritable;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

 public class testM extends Mapper<Text, BytesWritable, Text, Text> {

  public void map(Text ikey, BytesWritable ivalue, Context context) throws IOException, InterruptedException {

    //Read Current Image from File.
    BufferedImage img = ImageIO.read(new ByteArrayInputStream(ivalue.getBytes()));
    Tesseract instance = Tesseract.getInstance();           

    try {
        String text = instance.doOCR(img);          
        context.write(new Text("fff"), new Text("fff"));    

    } catch (TesseractException e) {

        context.write(new Text("fff"), new Text("fff"));            
        e.printStackTrace();
    }
    //String result = instance.doOCR(img);  

}
}

这是司机代码

public static void main(String[] args) throws Exception {

    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "Image2Text");
    job.setJarByClass(driver.class);
    job.setMapperClass(testM.class);

    // TODO: specify a reducer
    job.setReducerClass(Reducer.class);

    // TODO: specify output types
    //job.setOutputKeyClass(Text.class);
    //job.setOutputValueClass(Text.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);

    //input format
    job.setInputFormatClass(SequenceFileInputFormat.class);

    // TODO: specify input and output DIRECTORIES (not files)
    FileInputFormat.setInputPaths(job, new Path("inSeq"));
    FileOutputFormat.setOutputPath(job, new Path("out"));

    if (!job.waitForCompletion(true))
        return;
}

我尝试输出“fff”只是为了确保Map器正常工作,但正如我所说,它没有输出任何东西。如果我拆了线 String text = instance.doOCR(img); 一切正常。我检查序列文件的内容并查看 img 两个看起来都不错。有人知道问题出在哪里吗?

暂无答案!

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

相关问题