source: gs3-extensions/pharos/trunk/src/java/pharosimageis/PharosImageIS.java@ 21265

Last change on this file since 21265 was 21265, checked in by kjdon, 14 years ago

commented out some stuff in add which is now in constructor

File size: 6.5 KB
Line 
1package pharosimageis;
2
3import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub;
4import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub.QueryByID;
5import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub.QueryByIDResponse;
6import eu.pharos.kmi.videosegmentation.VSProcessor;
7import eu.pharos.kmi.videosegmentation.VSVideoBean;
8import eu.pharos.kmi.videosegmentation.VideoSegmentation;
9import java.io.File;
10import java.io.PrintStream;
11import mpegMpeg7Schema2001.MediaLocatorType;
12import mpegMpeg7Schema2001.Mpeg7Document;
13import mpegMpeg7Schema2001.Mpeg7Document.Factory;
14import org.apache.commons.io.FileUtils;
15import org.apache.xmlbeans.XmlObject;
16
17public class PharosImageIS
18{
19 private final String namespaceDeclaration = "declare namespace mpeg7='urn:mpeg:mpeg7:schema:2001';";
20 private final String query2 = "$this//mpeg7:MediaLocator";
21 private static ContentBasedSearchWSProxyStub cbsStub = null;
22 private static boolean proxy = false;
23 private static String proxyHost = null;
24 private static int proxyPort = 0;
25 private VSProcessor vsp = null;
26
27 public PharosImageIS()
28 {
29 if (!(VideoSegmentation.instanceCreated())){
30 VideoSegmentation.getInstance();
31 }
32 String video_endpoint = VideoSegmentation.getCbseWSEndpoint();
33 try {
34 this.cbsStub = new ContentBasedSearchWSProxyStub(video_endpoint);
35 } catch (Exception e) {
36 System.err.println(e);
37 }
38 }
39
40 public String query(String collection, String id) throws Exception {
41 ContentBasedSearchWSProxyStub.QueryByID req = new ContentBasedSearchWSProxyStub.QueryByID();
42 String input = query_xml;
43 input.replace("**docid**", collection+":"+id+".jpg");
44 req.setQuery(input);
45 ContentBasedSearchWSProxyStub.QueryByIDResponse res = getCbsStub().queryByID(req);
46 return res.get_return();
47 }
48
49 public static void main(String[] args)
50 {
51 try {
52
53 if (args.length != 1) {
54 System.out.println("USAGE: java -jar PharosImageIS.jar xmlinput.xml");
55 System.exit(0);
56 }
57 String dir = System.getProperty("user.dir");
58
59 File inputFile = new File(dir + System.getProperty("file.separator") + args[0]);
60
61 String input = FileUtils.readFileToString(new File(args[0]));
62
63 PharosImageIS inst = new PharosImageIS();
64
65 if (input.contains("kmi image annotation segment to add")) {
66 System.err.println("adding an image");
67 String imageLocation = inst.getImageLocation(inst.processMpeg7Input(input));
68
69 //String video_endpoint = VideoSegmentation.getCbseWSEndpoint();
70
71 //ContentBasedSearchWSProxyStub cbse_stub = new ContentBasedSearchWSProxyStub(video_endpoint);
72 //inst.setCbsStub(cbse_stub);
73 ////inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
74 inst.setVsp(new VSProcessor(VideoSegmentation.getWorkpath(), new VSVideoBean(imageLocation), inst.getCbsStub()));
75 inst.getVsp().processExistingKeyframes();
76 inst.getVsp().addLFImageDB();
77 System.out.println("TRUE");
78 }
79 else if (input.contains("kmi image annotation segment to remove")) {
80 String imageLocation = inst.getImageLocation(inst.processMpeg7Input(input));
81 inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
82 inst.setVsp(new VSProcessor(VideoSegmentation.getWorkpath(), new VSVideoBean(imageLocation), inst.getCbsStub()));
83
84 inst.getVsp().removeExistingKeyframes(input);
85 System.out.println("TRUE");
86 }
87 else if (input.contains("QueryByMedia")) {
88 inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
89 ContentBasedSearchWSProxyStub.QueryByID req = new ContentBasedSearchWSProxyStub.QueryByID();
90 req.setQuery(input);
91 ContentBasedSearchWSProxyStub.QueryByIDResponse res = inst.getCbsStub().queryByID(req);
92 FileUtils.writeStringToFile(new File(dir + System.getProperty("file.separator") + "image_cbs_result.xml"), res.get_return());
93 }
94 else {
95 throw new RuntimeException("Unsuported action" + input);
96 }
97 }
98 catch (Exception e) {
99 // System.out.println(e);
100 e.printStackTrace();
101 }
102 }
103
104 public static boolean isProxy()
105 {
106 return proxy;
107 }
108
109 public static void setProxy(boolean aProxy)
110 {
111 proxy = aProxy;
112 }
113
114 public static String getProxyHost()
115 {
116 return proxyHost;
117 }
118
119 public static void setProxyHost(String aProxyHost)
120 {
121 proxyHost = aProxyHost;
122 }
123
124 public static int getProxyPort()
125 {
126 return proxyPort;
127 }
128
129 public static void setProxyPort(int aProxyPort)
130 {
131 proxyPort = aProxyPort;
132 }
133
134 public ContentBasedSearchWSProxyStub getCbsStub()
135 {
136 return this.cbsStub;
137 }
138
139 public void setCbsStub(ContentBasedSearchWSProxyStub cbsStub)
140 {
141 this.cbsStub = cbsStub;
142 }
143
144 private String processMpeg7Input(String mpeg7) throws Exception
145 {
146 Mpeg7Document mpeg7doc = Mpeg7Document.Factory.parse(mpeg7);
147
148 if (!(mpeg7doc.validate())) {
149 System.out.println("Invalid instance!!!: " + mpeg7);
150 }
151
152 return getMediaURI(mpeg7doc);
153 }
154
155 private String getMediaURI(Mpeg7Document mpeg7doc)
156 {
157 XmlObject[] ml = mpeg7doc.selectPath("declare namespace mpeg7='urn:mpeg:mpeg7:schema:2001';$this//mpeg7:MediaLocator");
158 MediaLocatorType mlt = (MediaLocatorType)ml[0];
159 return mlt.getMediaUri().trim();
160 }
161
162 private String getImageLocation(String input) throws Exception {
163 if (input.startsWith("file://")) {
164 return input.substring("file://".length(), input.length());
165 }
166 return input;
167 }
168
169 public VSProcessor getVsp()
170 {
171 return this.vsp;
172 }
173
174 public void setVsp(VSProcessor vsp)
175 {
176 this.vsp = vsp;
177 }
178
179 private static String query_xml = "<MpegQuery mpqfID='TestId0012-36' xmlns='urn:mpeg:mpqf:schema:2008' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:mpeg7='urn:mpeg:mpeg7:schema:2004' xsi:schemaLocation='urn:mpeg:mpqf:schema:2008 mpqfv08.xsd urn:mpeg:mpeg7:schema:2004 M7v2schema.xsd'><Query><Input><!-- This is used to format the output / Result set --><OutputDescription maxItemCount='10' freeTextUse='true' mediaResourceUse='true' outputNameSpace='urn:mpeg:mpqf:schema:2008'></OutputDescription><QueryCondition><TargetMediaType>video/jpeg</TargetMediaType><Condition xsi:type='QueryByMedia' matchType='similar' thresholdValue='0.8' preferenceValue='1'><MediaResource resourceID='id001'><MediaResource><MediaUri>**docid**</MediaUri></MediaResource></MediaResource></Condition></QueryCondition><ServiceSelection><ServiceID>image-search-mediaid</ServiceID></ServiceSelection></Input></Query></MpegQuery>";
180
181
182}
183
Note: See TracBrowser for help on using the repository browser.