Ignore:
Timestamp:
2014-12-19T10:43:16+13:00 (9 years ago)
Author:
jmt12
Message:

Extending the Image document class with SIFT processing so as to trigger greater CPU load. Makes use of stream gobbler... gobble-gobble

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/video-and-audio/trunk/src/opt/Terrier/ImageDocument.java

    r26214 r29648  
    185185      logger.error("Exception while creating dummy text stream: ", e);
    186186    }
     187
     188    // Use OpenSIFT to generate a featureset (in Oxford format) for this image
     189    logger.info("ImageDocument - generate and record SIFT features");
     190    try
     191    {
     192      String sift_command[] = {
     193        "siftfeat",
     194        "-x",
     195        source_path.toString()
     196      };
     197      logger.info("ImageDocument - sift command: " + Arrays.toString(sift_command));
     198      Process sift_process = Runtime.getRuntime().exec(sift_command);
     199      // we'd usually send STDERR to /dev/null, but a streamgobbler is easier
     200      // in Java
     201      StreamGobbler sift_process_error_gobbler = new StreamGobbler(sift_process.getErrorStream());
     202      sift_process_error_gobbler.start();
     203      // the SIFT features, in Oxford format, will arrive from STDOUT
     204      BufferedReader sift_br = new BufferedReader(new InputStreamReader(sift_process.getInputStream()));
     205      String line;
     206      StringBuffer oxford_features;
     207      while ((line = sift_br.readLine()) != null)
     208      {
     209        oxford_features.append(line);
     210      }
     211      // this command blocks until process completes (emit return value) which
     212      // should be shortly after it emits the last line of SIFT feature data
     213      int sift_status = sift_process.waitFor();
     214      this.properties.put("sift", oxford_features.toString());
     215    }
     216    catch (Exception e)
     217    {
     218      logger.error("Exception while generating preview image: ", e);
     219    }
     220
    187221    logger.info("ImageDocument - Complete!");
    188222  }
Note: See TracChangeset for help on using the changeset viewer.