source: gs3-extensions/structured-image/trunk/perllib/plugins/GoogleVisionImagePlugin.pm@ 37000

Last change on this file since 37000 was 37000, checked in by davidb, 17 months ago

Changes after testing

File size: 2.9 KB
Line 
1######################################################################
2#
3# GoogleVisionImagePlugin.pm -- plugin that extends the capability of
4# ImagePlugin to use Google Vision API allowing for: metadata labelling
5# of objects within a scene; OCR text recognition.
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 1999 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29package GoogleVisionImagePlugin;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34
35use utf8;
36use JSON qw( from_json );
37
38#use Data::Dumper;
39
40use gsprintf;
41use FileUtils;
42
43use ImagePlugin;
44use GoogleVisionAPIConverter;
45
46
47sub BEGIN {
48 @GoogleVisionImagePlugin::ISA = ('ImagePlugin', 'GoogleVisionAPIConverter');
49}
50
51my $arguments = [];
52
53
54my $options = { 'name' => "GoogleVisionImagePlugin",
55 'desc' => "{GoogleVisionImagePlugin.desc}",
56 'abstract' => "no",
57 'inherits' => "yes",
58 'args' => $arguments };
59
60sub new {
61 my ($class) = shift (@_);
62 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
63 push(@$pluginlist, $class);
64
65 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
66 push(@{$hashArgOptLists->{"OptList"}},$options);
67
68 new GoogleVisionAPIConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
69 my $self = new ImagePlugin($pluginlist, $inputargs, $hashArgOptLists);
70
71 return bless $self, $class;
72}
73
74
75# do plugin specific processing of doc_obj
76sub process {
77 my $self = shift (@_);
78 # options??
79 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
80
81 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
82 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
83 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
84
85 $self->run_gv_convert($filename_full_path,$url_encoded_filename,$doc_obj);
86
87 $self->SUPER::process(@_);
88}
89
901;
91
92
93
94
95
96
97
98
99
100
101
Note: See TracBrowser for help on using the repository browser.