我正在使用 OpenIMAJ 库,它在“JPEG”和“PNG”文件上运行良好,但在 tiff 文件上它给了我一个错误。这是代码:
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.MBFImage;
....
File file = new File("/home/mosab/Desktop/input/tif.tif");
MBFImage input = ImageUtilities.readMBF(file);
这是错误:
Exception in thread "main" java.io.IOException: org.apache.sanselan.ImageReadException: Tiff: unknown compression: 7
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:189)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:126)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:355)
at org.mosab.TestOpenIMAJ.TestKmeans.main(TestKmeans.java:49)
Caused by: org.apache.sanselan.ImageReadException: Tiff: unknown compression: 7
at org.apache.sanselan.formats.tiff.datareaders.DataReader.decompress(DataReader.java:135)
at org.apache.sanselan.formats.tiff.datareaders.DataReaderStrips.readImageData(DataReaderStrips.java:96)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:505)
at org.apache.sanselan.formats.tiff.TiffDirectory.getTiffImage(TiffDirectory.java:163)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:441)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1264)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1163)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1136)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:187)
... 3 more
这是我正在使用的 tiff 文件(特别是 GeoTiff):
“ https://drive.google.com/file/d/0ByKaCojxzNa9MWxPTUJjZURHR1E/view?usp=sharing ”
这是否意味着 OpenIMAJ 库不支持 tiff 格式/GeoTiff?
我认为 OpenIMAJ 不支持 tiff,所以我尝试使用“TwelveMonkeys”库来读取该文件。“TwelveMonkeys”库单独/单独能够读取文件。因此,我导入了 TwelveMonkeys 库以与 OpenIMAJ 一起工作,因此支持 tiff 文件,这适用于某些 tiff 文件,但对于该文件它不起作用(尽管“TwelveMonkeys”能够在单独的项目中单独读取它)并且我得到了这个例外:
Exception in thread "main" java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:448)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:185)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:126)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:355)
at org.mosab.TestOpenIMAJ.TestKmeans.main(TestKmeans.java:49)
后来,当我跟踪错误消息时,我发现某些内容可能与文件的大小有关,因为它大约为26mb,我注意到错误源于类“org.openimaj.image.ExtendedImageIO”的“读取”方法,我认为它使用最大10mb的大小:
public static BufferedImage read(InputStream input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("input == null!");
}
final NonClosableInputStream buffer = new NonClosableInputStream(input);
buffer.mark(10 * 1024 * 1024); // 10mb I think here is the problem
BufferedImage bi;
try {
bi = readInternal(buffer);
} catch (final Exception ex) {
bi = null;
}
if (bi == null) {
buffer.reset();
try {
bi = Sanselan.getBufferedImage(buffer);
} catch (final Throwable e) {
throw new IOException(e);
}
}
return bi;
}
那么我该如何解决这个问题并在 OpenIMAJ 中读取该 tiff 文件(为了进一步应用设施,OpenIMAJ 提供了类似集群/分段的功能)?