Index: /gs3-extensions/openCV/trunk/src/perllib/plugins/AdvImagePlugin.pm
===================================================================
--- /gs3-extensions/openCV/trunk/src/perllib/plugins/AdvImagePlugin.pm	(revision 29119)
+++ /gs3-extensions/openCV/trunk/src/perllib/plugins/AdvImagePlugin.pm	(revision 29119)
@@ -0,0 +1,137 @@
+###########################################################################
+#
+# AdvImagePlugin.pm -- extends the standard ImagePlugin with feature
+#                      extraction using the OpenSIFT program.  SIFT, in
+#                      turn requires the OpenCV libraries.
+#
+# A component of the Greenstone digital library software from the New
+# Zealand Digital Library Project at the University of Waikato, New
+# Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+package AdvImagePlugin;
+
+use ImagePlugin;
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and viceversa
+no strict 'subs';
+
+use gsprintf 'gsprintf';
+
+sub BEGIN {
+    @AdvImagePlugin::ISA = ('ImagePlugin');
+}
+
+my $arguments =
+    [ { 'name' => "process_exp",
+	'desc' => "{BasePlugin.process_exp}",
+	'type' => "regexp",
+	'deft' => &get_default_process_exp(),
+	'reqd' => "no" },
+      ];
+
+my $options = { 'name'     => "AdvImagePlugin",
+		'desc'     => "{ImagePlugin.desc}",
+		'abstract' => "no",
+		'inherits' => "yes",
+		'args'     => $arguments };
+
+
+## @function
+#
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+    my $self = new ImagePlugin($pluginlist, $inputargs, $hashArgOptLists);
+    $self->{'sift_available'} = 0;
+    return bless $self, $class;
+}
+##
+
+
+## @function
+#
+sub init {
+  my $self = shift (@_);
+  my ($verbosity, $outhandle, $failhandle) = @_;
+  $self->SUPER::init(@_);
+  # Test that OpenSIFT is available... otherwise nothing else is going to work
+  my $sift_version = `siftfeat -h 2>&1`;
+  if ($sift_version =~ /siftfeat version \d+\.\d+\.\d+/)
+  {
+    $self->{'sift_available'} = 1;
+  }
+}
+##
+
+
+## @function
+# - for now we'll restrict to JPGs because I know OpenSIFT likes them
+sub get_default_process_exp {
+  my $self = shift (@_);
+  return q^(?i)\.(jpe?g)$^;
+}
+##
+
+
+## @function
+# do plugin specific processing of doc_obj
+sub process {
+  my $self = shift (@_);
+  my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
+
+  $self->SUPER::process($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli);
+
+  my $outhandle = $self->{'outhandle'};
+  my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
+
+
+  if ($self->{'sift_available'} == 1)
+  {
+    # we call SIFT on the image, and then read the Oxford formatted features
+    # from STDOUT
+    # any other messages on STDERR are sent to nullsville
+    my $sift_command = 'siftfeat -x "' . $filename_full_path . '" 2>/dev/null';
+    my $oxfd_features = `$sift_command`;
+    $doc_obj->add_metadata ($doc_obj->get_top_section(), "SIFTOXFDFeatures", $oxfd_features);
+  }
+  else
+  {
+    print STDERR 'Warning! SIFT features cannot be extracted: ' . $file . "\n";
+  }
+  return 1;
+}
+
+1;
+
+
+
+
+
+
+
+
+
+
+
