[21237] | 1 |
|
---|
| 2 |
|
---|
| 3 | import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub;
|
---|
| 4 | import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub.QueryByID;
|
---|
| 5 | import eu.pharos.kmi.videosegmentation.ContentBasedSearchWSProxyStub.QueryByIDResponse;
|
---|
| 6 | import eu.pharos.kmi.videosegmentation.VSProcessor;
|
---|
| 7 | import eu.pharos.kmi.videosegmentation.VSVideoBean;
|
---|
| 8 | import eu.pharos.kmi.videosegmentation.VideoSegmentation;
|
---|
| 9 | import java.io.File;
|
---|
| 10 | import java.io.PrintStream;
|
---|
| 11 | import mpegMpeg7Schema2001.MediaLocatorType;
|
---|
| 12 | import mpegMpeg7Schema2001.Mpeg7Document;
|
---|
| 13 | import mpegMpeg7Schema2001.Mpeg7Document.Factory;
|
---|
| 14 | import org.apache.commons.io.FileUtils;
|
---|
| 15 | import org.apache.xmlbeans.XmlObject;
|
---|
| 16 |
|
---|
| 17 | public 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 | String imageLocation = inst.getImageLocation(inst.processMpeg7Input(input));
|
---|
| 67 |
|
---|
| 68 | String video_endpoint = VideoSegmentation.getCbseWSEndpoint();
|
---|
| 69 |
|
---|
| 70 | ContentBasedSearchWSProxyStub cbse_stub = new ContentBasedSearchWSProxyStub(video_endpoint);
|
---|
| 71 | inst.setCbsStub(cbse_stub);
|
---|
| 72 | //inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
|
---|
| 73 | inst.setVsp(new VSProcessor(VideoSegmentation.getWorkpath(), new VSVideoBean(imageLocation), inst.getCbsStub()));
|
---|
| 74 | inst.getVsp().processExistingKeyframes();
|
---|
| 75 | inst.getVsp().addLFImageDB();
|
---|
| 76 | System.out.println("TRUE");
|
---|
| 77 | }
|
---|
| 78 | else if (input.contains("kmi image annotation segment to remove")) {
|
---|
| 79 | String imageLocation = inst.getImageLocation(inst.processMpeg7Input(input));
|
---|
| 80 | inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
|
---|
| 81 | inst.setVsp(new VSProcessor(VideoSegmentation.getWorkpath(), new VSVideoBean(imageLocation), inst.getCbsStub()));
|
---|
| 82 |
|
---|
| 83 | inst.getVsp().removeExistingKeyframes(input);
|
---|
| 84 | System.out.println("TRUE");
|
---|
| 85 | }
|
---|
| 86 | else if (input.contains("QueryByMedia")) {
|
---|
| 87 | inst.setCbsStub(new ContentBasedSearchWSProxyStub(VideoSegmentation.getCbseWSEndpoint()));
|
---|
| 88 | ContentBasedSearchWSProxyStub.QueryByID req = new ContentBasedSearchWSProxyStub.QueryByID();
|
---|
| 89 | req.setQuery(input);
|
---|
| 90 | ContentBasedSearchWSProxyStub.QueryByIDResponse res = inst.getCbsStub().queryByID(req);
|
---|
| 91 | FileUtils.writeStringToFile(new File(dir + System.getProperty("file.separator") + "image_cbs_result.xml"), res.get_return());
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | throw new RuntimeException("Unsuported action" + input);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | catch (Exception e) {
|
---|
| 98 | // System.out.println(e);
|
---|
| 99 | e.printStackTrace();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | public static boolean isProxy()
|
---|
| 104 | {
|
---|
| 105 | return proxy;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public static void setProxy(boolean aProxy)
|
---|
| 109 | {
|
---|
| 110 | proxy = aProxy;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public static String getProxyHost()
|
---|
| 114 | {
|
---|
| 115 | return proxyHost;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | public static void setProxyHost(String aProxyHost)
|
---|
| 119 | {
|
---|
| 120 | proxyHost = aProxyHost;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public static int getProxyPort()
|
---|
| 124 | {
|
---|
| 125 | return proxyPort;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public static void setProxyPort(int aProxyPort)
|
---|
| 129 | {
|
---|
| 130 | proxyPort = aProxyPort;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | public ContentBasedSearchWSProxyStub getCbsStub()
|
---|
| 134 | {
|
---|
| 135 | return this.cbsStub;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | public void setCbsStub(ContentBasedSearchWSProxyStub cbsStub)
|
---|
| 139 | {
|
---|
| 140 | this.cbsStub = cbsStub;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | private String processMpeg7Input(String mpeg7) throws Exception
|
---|
| 144 | {
|
---|
| 145 | Mpeg7Document mpeg7doc = Mpeg7Document.Factory.parse(mpeg7);
|
---|
| 146 |
|
---|
| 147 | if (!(mpeg7doc.validate())) {
|
---|
| 148 | System.out.println("Invalid instance!!!: " + mpeg7);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | return getMediaURI(mpeg7doc);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | private String getMediaURI(Mpeg7Document mpeg7doc)
|
---|
| 155 | {
|
---|
| 156 | XmlObject[] ml = mpeg7doc.selectPath("declare namespace mpeg7='urn:mpeg:mpeg7:schema:2001';$this//mpeg7:MediaLocator");
|
---|
| 157 | MediaLocatorType mlt = (MediaLocatorType)ml[0];
|
---|
| 158 | return mlt.getMediaUri().trim();
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | private String getImageLocation(String input) throws Exception {
|
---|
| 162 | if (input.startsWith("file://")) {
|
---|
| 163 | return input.substring("file://".length(), input.length());
|
---|
| 164 | }
|
---|
| 165 | return input;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | public VSProcessor getVsp()
|
---|
| 169 | {
|
---|
| 170 | return this.vsp;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | public void setVsp(VSProcessor vsp)
|
---|
| 174 | {
|
---|
| 175 | this.vsp = vsp;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | 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>";
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | }
|
---|
| 182 |
|
---|