Make region optional in textInRegion functions.

This commit is contained in:
Albert Cervera i Areny 2009-03-14 18:08:32 +01:00
parent 49e5d3d40c
commit 2cbba682f0
4 changed files with 11 additions and 46 deletions

View File

@ -43,10 +43,10 @@ class Analyzer:
def scan(self, image):
pass
def textInRegion(self, region):
def textInRegion(self, region=None):
pass
def featureRectInRegion(self, region):
def featureRectInRegion(self, region=None):
pass
# Spawn process and return STDOUT

View File

@ -54,19 +54,19 @@ class Barcode(Analyzer):
print "Text: %s, Type: %s, Position: %f, %f" % (x.text, x.type, x.position.x(), x.position.y())
## @brief Returns all barcode values concatenated for a given region of the image.
def textInRegion(self, region):
def textInRegion(self, region=None):
for x in self.boxes:
if region.contains(x.position):
if not region or region.contains(x.position):
return unicode(x.text)
# Always return unicode strings
return u''
## @brief Returns the bounding rectangle of the text returned by textInRegion for
# the given region.
def featureRectInRegion(self, region):
def featureRectInRegion(self, region=None):
rect = QRectF()
for x in self.boxes:
if region.contains(x.position):
if not region or region.contains(x.position):
rect = rect.united( QRectF( x.position, x.position ) )
return rect

View File

@ -103,10 +103,10 @@ class DataMatrix(Analyzer):
print "Text: '%s'; Position: %f, %f; Size: %f, %f;" % (x.text, x.box.x(), x.box.y(), x.box.width(), x.box.height() )
## @brief Returns all data matrix values concatenated for a given region of the image.
def textInRegion(self, region):
def textInRegion(self, region=None):
texts = []
for x in self.boxes:
if region.intersects(x.box):
if not region or region.intersects(x.box):
texts.append( unicode(x.text) )
# Always return unicode strings
@ -114,10 +114,10 @@ class DataMatrix(Analyzer):
## @brief Returns the bounding rectangle of the text returned by textInRegion for
# the given region.
def featureRectInRegion(self, region):
def featureRectInRegion(self, region=None):
rect = QRectF()
for x in self.boxes:
if region.intersects(x.box):
if not region or region.intersects(x.box):
rect = rect.united( x.box )
return rect
@ -138,7 +138,7 @@ class DataMatrix(Analyzer):
self.parseOutput( content )
self.printBoxes()
Analyzer.registerAnalyzer( 'dataMatrix', DataMatrix )
#Analyzer.registerAnalyzer( 'dataMatrix', DataMatrix )
if __name__ == '__main__':
d = DataMatrix()

View File

@ -1,35 +0,0 @@
##############################################################################
#
# Copyright (c) 2008 Albert Cervera i Areny <albert@nan-tic.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
{
'scanner': {
'model':'.*',
'string': _('Scan Documents'),
'action': 'scan.scan'
}
}