1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # GoogleVisionPagedImagePlugin.pm -- plugin that adds Google Vision API
|
---|
4 | # capabilities on top of PageImagePlugin
|
---|
5 | #
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 |
|
---|
29 | # See PagedImagePlugin for more details
|
---|
30 |
|
---|
31 | package GoogleVisionPagedImagePlugin;
|
---|
32 |
|
---|
33 | #use Encode;
|
---|
34 | #use ReadXMLFile;
|
---|
35 | #use ReadTextFile;
|
---|
36 | use GoogleVisionAPIConverter;
|
---|
37 | use PagedImagePlugin;
|
---|
38 |
|
---|
39 | use strict;
|
---|
40 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
41 |
|
---|
42 | sub BEGIN {
|
---|
43 | @GoogleVisionPagedImagePlugin::ISA = ('PagedImagePlugin', 'GoogleVisionAPIConverter');
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | my $arguments = [];
|
---|
48 |
|
---|
49 | my $options = { 'name' => "GoogleVisionPagedImagePlugin",
|
---|
50 | 'desc' => "{GoogleVisionPagedImagePlugin.desc}",
|
---|
51 | 'abstract' => "no",
|
---|
52 | 'inherits' => "yes",
|
---|
53 | 'args' => $arguments };
|
---|
54 |
|
---|
55 | sub new {
|
---|
56 |
|
---|
57 | my ($class) = shift (@_);
|
---|
58 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
59 | push(@$pluginlist, $class);
|
---|
60 |
|
---|
61 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
62 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
63 |
|
---|
64 | new GoogleVisionAPIConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
|
---|
65 | my $self = new PagedImagePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
66 |
|
---|
67 | return bless $self, $class;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | #sub init {
|
---|
72 | # my $self = shift (@_);
|
---|
73 | # my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
74 | #
|
---|
75 | # $self->SUPER::init(@_);
|
---|
76 | # $self->GoogleVisionAPIConverter::init();
|
---|
77 | #}
|
---|
78 |
|
---|
79 | sub begin {
|
---|
80 | my $self = shift (@_);
|
---|
81 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
82 |
|
---|
83 | $self->SUPER::begin(@_);
|
---|
84 | $self->GoogleVisionAPIConverter::begin(@_);
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | sub init_new_doc_item
|
---|
89 | {
|
---|
90 | my $self = shift (@_);
|
---|
91 | my ($filename_full_path, $processor, $metadata) = @_;
|
---|
92 |
|
---|
93 | my $doc_obj = $self->SUPER::init_new_doc_item(@_);
|
---|
94 |
|
---|
95 | $self->{'gv-dococr-json-filename-recs'} = [];
|
---|
96 |
|
---|
97 | return $doc_obj;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | sub process_image {
|
---|
102 | my $self = shift(@_);
|
---|
103 | my ($filename_full_path, $filename_no_path, $doc_obj, $section, $rotate) = @_;
|
---|
104 |
|
---|
105 | my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
|
---|
106 | my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
|
---|
107 |
|
---|
108 | $self->run_gv_convert($filename_full_path,$url_encoded_filename,$doc_obj,$section);
|
---|
109 |
|
---|
110 | return $self->SUPER::process_image(@_);
|
---|
111 | }
|
---|
112 |
|
---|
113 | sub post_process_doc_obj {
|
---|
114 | my $self = shift (@_);
|
---|
115 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
116 |
|
---|
117 | my $ret_val_ok = $self->SUPER::post_process_doc_obj(@_);
|
---|
118 |
|
---|
119 | if ($ret_val_ok) {
|
---|
120 | $ret_val_ok = $self->opt_run_gen_openannotation($doc_obj);
|
---|
121 | }
|
---|
122 |
|
---|
123 | return $ret_val_ok;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | 1;
|
---|