From 2cbba682f039b3dc7afd672ac2296fb5776cca7c Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Sat, 14 Mar 2009 18:08:32 +0100 Subject: [PATCH] Make region optional in textInRegion functions. --- NanScan/Analyzer.py | 4 ++-- NanScan/Barcode.py | 8 ++++---- NanScan/DataMatrix.py | 10 +++++----- scan/__terp__.py | 35 ----------------------------------- 4 files changed, 11 insertions(+), 46 deletions(-) delete mode 100644 scan/__terp__.py diff --git a/NanScan/Analyzer.py b/NanScan/Analyzer.py index 7599b70..23f1ebe 100644 --- a/NanScan/Analyzer.py +++ b/NanScan/Analyzer.py @@ -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 diff --git a/NanScan/Barcode.py b/NanScan/Barcode.py index 3a26934..851894c 100644 --- a/NanScan/Barcode.py +++ b/NanScan/Barcode.py @@ -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 diff --git a/NanScan/DataMatrix.py b/NanScan/DataMatrix.py index 8b8a74e..258f45c 100644 --- a/NanScan/DataMatrix.py +++ b/NanScan/DataMatrix.py @@ -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() diff --git a/scan/__terp__.py b/scan/__terp__.py deleted file mode 100644 index bc34d46..0000000 --- a/scan/__terp__.py +++ /dev/null @@ -1,35 +0,0 @@ -############################################################################## -# -# Copyright (c) 2008 Albert Cervera i Areny -# -# 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' - } -} -