source: gs3-extensions/pharos/trunk/perllib/plugins/PharosImageIndexer.pm@ 21294

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

pharos plugin moved to extension folder rather than cluttering up main gs plugins. Now there are two: PharosImagePlugin is a top level plugin that inherits from ImagePLugin, and adds in the image similarity indexing functionality provided by PharosImageIndexer helper plugin. PharosImageINdexer will be used in future by PharosVideoPlugin. PharosIMagePlugin may include in future pharos annotation help plugin

File size: 4.5 KB
RevLine 
[21294]1###########################################################################
2#
3# PharosImageIndexer - helper plugin that does image conversion using ImageMagick
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 2008 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26package PharosImageIndexer;
27
28use PrintInfo;
29
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34use gsprintf 'gsprintf';
35
36BEGIN {
37 @PharosImageIndexer::ISA = ('PrintInfo');
38}
39
40my $arguments = [
41 { 'name' => "disable_pharos_imageis",
42 'desc' => "{PharosImageIndexer.disable_pharos_imageis}",
43 'type' => "flag",
44 'reqd' => "no" },
45 ];
46
47my $options = { 'name' => "PharosImageIndexer",
48 'desc' => "{PharosImageIndexer.desc}",
49 'abstract' => "yes",
50 'inherits' => "yes",
51 'args' => $arguments };
52
53sub new {
54 my ($class) = shift (@_);
55 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
56 push(@$pluginlist, $class);
57
58 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
59 push(@{$hashArgOptLists->{"OptList"}},$options);
60
61 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
62
63
64 return bless $self, $class;
65
66}
67
68# needs to be called after BasePlugin init, so that outhandle is set up.
69sub init {
70 my $self = shift(@_);
71
72 return if ($self->{'disable_pharos_imageis'});
73
74 # Check that Pharos is installed and available on the path
75 my $pharos_available = 1;
76 ## change for windows!
77 #my $result = `phraros-imageis-identify 2>&1`;
78 #my $return_value = $?;
79 #if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) { # Linux and Windows return different values for "program not found"
80 # $pharos_available = 0;
81 #}
82
83 $self->{'pharos_available'} = 1; #$pharos_available;
84
85 if ($self->{'pharos_available'} == 0) {
86 my $outhandle = $self->{'outhandle'};
87 &gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
88 }
89
90}
91
92sub begin {
93
94}
95
96sub removeold {
97 my $self = shift (@_);
98 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
99
100 print STDERR "removeold pharos plugin\n";
101 return if ($self->{'disable_pharos_imageis'});
102
103 if (!$self->{'pharos_available'}) {
104 print STDERR "pharos not available, not doing a removeold\n";
105 return;
106 }
107 # need to delete everything from the derby database.
108 my $collection = &util::get_current_collection_name();
109 my $cmd = "perl -S pharos-imageis-delete.pl $collection *.jpg 2>&1";
110 print STDERR "Running command $cmd\n";
111 my $result = `$cmd`;
112 my $return_value = $?;
113 my $outhandle = $self->{'outhandle'};
114 if ($return_value != 0) {
115 print $outhandle "Pharos Indexing failed to clear database for collection $collection\n";
116 }
117 print $outhandle "$result\n";
118
119}
120
121sub pharos_index_image {
122 my $self = shift(@_);
123
124 return if ($self->{'disable_pharos_imageis'} || !$self->{'pharos_available'});
125 # pass in the jpg thumbnail, and the doc obj
126 my ($filename_full_path, $doc_obj) = @_;
127 print STDERR "pharos indexing $filename_full_path\n";
128
129 my $collection = &util::get_current_collection_name();
130 my $id = $doc_obj->get_OID();
131
132 my $cmd = "perl -S pharos-imageis-add.pl $collection $filename_full_path $id 2>&1";
133 print STDERR "Running command $cmd\n";
134 my $result = `$cmd`;
135
136 my $return_value = $?;
137 my $outhandle = $self->{'outhandle'};
138 if ($return_value != 0) {
139 print $outhandle "Pharos Indexing failed for $filename_full_path, $id\n";
140 }
141 print $outhandle "$result\n";
142
143}
144
145
1461;
Note: See TracBrowser for help on using the repository browser.