gpt4 book ai didi

image - 从Hadoop sequenceFile获取原始图像时出错

转载 作者:行者123 更新时间:2023-12-02 21:48:26 24 4
gpt4 key购买 nike

我首先将所有图像打包到Hadoop sequenceFile中:

FSDataInputStream in = null;    
in = fs.open(new Path(uri)); //uri is the image location in HDFS
byte buffer[] = new byte[in.available()];
in.read(buffer);
context.write(imageID, new BytesWritable(buffer));

然后,我想从Reducer中的Sequence文件中获取原始图像:
BufferedImage imag;    
imag = ImageIO.read(new ByteArrayInputStream(value.getBytes()));

但由于我遇到此错误,因此无法正确获取图像:
Error: javax.imageio.IIOException: Error reading PNG image data
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream

我的问题是如何从hadoop的序列文件中获取原始图像?

最佳答案

问题是我使用错误的方式读取流。这是正确的方法:

import org.apache.commons.io.IOUtils;
Configuration confHadoop = new Configuration();
FileSystem fs = FileSystem.get(confHadoop);
Path file = new Path(fs.getUri().toString() + "/" + fileName);
in = fs.open(file);
byte[] buffer = IOUtils.toByteArray(in);

然后可以通过 new BytesWritable(buffer)将缓冲区写入sequenceFile。
从sequenceFile读取时相同。

关于image - 从Hadoop sequenceFile获取原始图像时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180296/

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