OpenIMAJ-读取保存为ascii的功能列表时出错



使用OpenIMAJ时,我想保存功能列表以备日后使用,但在重新读取刚刚保存的功能文件时,出现了java.util.NoSuchElementException: No line found异常(见下文)。我已经检查了文本文件是否存在,尽管我真的不确定完整的内容是否是应该的(它很长)。

有什么想法吗?

提前感谢!

(我的试用代码粘贴在下面)。

java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Unknown Source)
    at org.openimaj.image.feature.local.keypoints.Keypoint.readASCII(Keypoint.java:296)
    at org.openimaj.feature.local.list.LocalFeatureListUtils.readASCII(LocalFeatureListUtils.java:170)
    at org.openimaj.feature.local.list.LocalFeatureListUtils.readASCII(LocalFeatureListUtils.java:136)
    at org.openimaj.feature.local.list.MemoryLocalFeatureList.read(MemoryLocalFeatureList.java:134)
    ... 

我的试用代码如下:

Video<MBFImage> originalVideo = getVideo();
MBFImage frame = originalVideo.getCurrentFrame().clone();
DoGSIFTEngine engine = new DoGSIFTEngine();
LocalFeatureList<Keypoint> originalFeatureList = engine.findFeatures(frame.flatten());
try {
    originalFeatureList.writeASCII(new PrintWriter(new File("featureList.txt")));
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
System.out.println("Saved feature list with "+originalFeatureList.size()+" keypoints.");
MemoryLocalFeatureList<Keypoint> loadedFeatureList = null;
try {
    loadedFeatureList = MemoryLocalFeatureList.read(new File("featureList.txt"), Keypoint.class);
} catch (IOException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
System.out.println("Loaded feature list with "+loadedFeatureList.size()+" keypoints.");

我认为问题在于您没有关闭用于保存特性的PrintWriter,而且它还没有时间真正编写内容。但是,您不应该直接使用LocalFeatureList.writeASCII方法,因为它不会写入标头信息;而是使用CCD_ 4。替换:

originalFeatureList.writeASCII(new PrintWriter(new File("featureList.txt")));

带有

IOUtils.writeASCII(new File("featureList.txt"), originalFeatureList);

然后它就会起作用。这也涉及到在文件写入后关闭它。

最新更新