1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.openimaj.experiment.gmm.retrieval;
31
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import org.apache.commons.vfs2.FileObject;
37 import org.apache.commons.vfs2.FileSystemException;
38 import org.apache.commons.vfs2.FileSystemManager;
39 import org.apache.commons.vfs2.VFS;
40 import org.openimaj.data.dataset.ReadableListDataset;
41 import org.openimaj.data.identity.Identifiable;
42 import org.openimaj.io.ObjectReader;
43
44
45
46
47
48
49 public class UKBenchListDataset<IMAGE> extends ReadableListDataset<IMAGE, FileObject> implements Identifiable{
50 private int object;
51 private List<String> ids;
52 private FileObject base;
53
54
55
56
57
58
59 public UKBenchListDataset(String path, ObjectReader<IMAGE, FileObject> reader, int object) {
60 super(reader);
61 this.object = object;
62 this.ids = heldIDs();
63 FileSystemManager fsManager;
64 try {
65 fsManager = VFS.getManager();
66 this.base = fsManager.resolveFile(path);
67 } catch (FileSystemException e) {
68 throw new RuntimeException(e);
69 }
70 }
71 @Override
72 public IMAGE getInstance(int index) {
73 FileObject fo = null;
74 try {
75 fo = createFileObject(this.ids.get(index));
76 return this.reader.read(fo);
77 } catch (IOException e) {
78 throw new RuntimeException(e);
79 } finally {
80 if(fo!=null){
81 try {
82 fo.close();
83 } catch (FileSystemException e) {
84 throw new RuntimeException(e);
85 }
86 }
87 }
88 }
89
90 private FileObject createFileObject(String string) {
91 try {
92 FileObject child = base.getChild(string);
93 return child;
94 } catch (FileSystemException e) {
95 throw new RuntimeException(e);
96 }
97 }
98 @Override
99 public int numInstances() {
100 return 4;
101 }
102
103 @Override
104 public String getID() {
105 List<String> ids = heldIDs();
106 return String.format("UKBench{%s}",ids.toString());
107 }
108 private List<String> heldIDs() {
109 List<String> ids = new ArrayList<String>();
110 ids.add(String.format("ukbench%05d.jpg",object * 4 + 0));
111 ids.add(String.format("ukbench%05d.jpg",object * 4 + 1));
112 ids.add(String.format("ukbench%05d.jpg",object * 4 + 2));
113 ids.add(String.format("ukbench%05d.jpg",object * 4 + 3));
114 return ids;
115 }
116
117
118
119 public int getObject() {
120 return object;
121 }
122
123
124
125 }