[ocrfeeder] layoutAnalysis: Delete trailing whitespaces
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] layoutAnalysis: Delete trailing whitespaces
- Date: Thu, 1 Jul 2010 09:56:44 +0000 (UTC)
commit e670f1117005ca30886255d3ab31a430c6eb5dd5
Author: Joaquim Rocha <jrocha igalia com>
Date: Thu Jul 1 10:55:08 2010 +0200
layoutAnalysis: Delete trailing whitespaces
feeder/layoutAnalysis.py | 82 +++++++++++++++++++++++-----------------------
1 files changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/feeder/layoutAnalysis.py b/feeder/layoutAnalysis.py
index edab8a5..984e546 100644
--- a/feeder/layoutAnalysis.py
+++ b/feeder/layoutAnalysis.py
@@ -3,7 +3,7 @@
###########################################################################
# OCRFeeder - The complete OCR suite
# Copyright (C) 2009 Joaquim Rocha
-#
+#
# 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 3 of the License, or
@@ -19,42 +19,42 @@
###########################################################################
from util.lib import debug
-from util.constants import OCRFEEDER_DEBUG
+from util.constants import OCRFEEDER_DEBUG
NONE = 0
TOP = -1
BOTTOM = 1
BOTH = 2
class Block:
-
+
def __init__(self, start_line, finish_line, first_one, last_one=-1, extra_charge=0):
self.start_line = start_line
self.finish_line = finish_line
self.first_one = first_one
self.last_one = last_one
self.extra_charge = extra_charge
-
+
def isSingle(self):
return self.start_line == self.finish_line and self.last_one != -1
-
+
def checkSingleBlockBounds(self, block):
return block.first_one != -1 and self.first_one >= block.first_one and self.last_one <= block.last_one
-
+
def chargeExtraTop(self):
if self.extra_charge == BOTTOM:
self.extra_charge = BOTH
else:
self.extra_charge = TOP
-
+
def chargeExtraBottom(self):
if self.extra_charge == TOP:
self.extra_charge = BOTH
else:
self.extra_charge = BOTTOM
-
+
def testJoin(self, block):
return self.extra_charge > 0 and (block.extra_charge == BOTH or block.extra_charge == TOP)
-
+
def normalizeExtra(self, block):
if (self.extra_charge == TOP or self.extra_charge == BOTH) and block.extra_charge > 0:
self.extra_charge = BOTH
@@ -64,34 +64,34 @@ class Block:
self.extra_charge = BOTTOM
else:
self.extra_charge = NONE
-
+
def decreaseStartLine(self, number_of_lines):
self.start_line -= number_of_lines
if self.extra_charge == TOP:
self.extra_charge = NONE
elif self.extra_charge == BOTH:
self.extra_charge = BOTTOM
-
+
def increaseStartLine(self, number_of_lines):
self.start_line += number_of_lines
if self.extra_charge == BOTTOM:
self.extra_charge = NONE
elif self.extra_charge == BOTH:
self.extra_charge = TOP
-
+
def increaseFinishLine(self, number_of_lines):
self.finish_line += number_of_lines
if self.extra_charge == BOTH:
self.extra_charge = TOP
elif self.extra_charge == BOTTOM:
self.extra_charge = NONE
-
+
def __getVerticalRange(self):
return xrange(self.start_line, self.finish_line + 1)
-
+
def __getHorizontalRange(self):
return xrange(self.first_one, self.last_one + 1)
-
+
def __inVerticalRange(self, verticalRange):
begin = self.start_line
end = self.finish_line
@@ -100,13 +100,13 @@ class Block:
elif self.extra_charge == BOTTOM or self.extra_charge == BOTH:
end +=1
return (begin in verticalRange[:-1]) or (end in verticalRange[1])
-
- def __inHorizontalRange(self, horizontalRange):
+
+ def __inHorizontalRange(self, horizontalRange):
return (self.first_one in horizontalRange) or (self.last_one in horizontalRange)
-
- def equals(self,block):
+
+ def equals(self,block):
return self.start_line == block.start_line and self.finish_line == block.finish_line and self.first_one == block.first_one and self.last_one == block.last_one
-
+
def colides(self, block):
vertical_range = self.__getVerticalRange()
if block.__inHorizontalRange(self.__getHorizontalRange()):
@@ -119,7 +119,7 @@ class Block:
if self.start_line - 1 == block.finish_line:
return True
return False
-
+
def translateToUnits(self, window_size):
leftmost_x = self.first_one * window_size
rightmost_x = self.last_one * window_size + window_size
@@ -130,7 +130,7 @@ class Block:
if self.extra_charge > 0:
lowest_y += window_size / 2.0
return leftmost_x, highest_y, rightmost_x, lowest_y
-
+
def __str__(self):
block_str = """
Block ::::::::::::
@@ -139,18 +139,18 @@ Block ::::::::::::
First one: %(first)s
Last one: %(last)s
Extra charge: %(extra)s
-""" % {'start': self.start_line, 'finish': self.finish_line,
- 'first': self.first_one, 'last': self.last_one,
+""" % {'start': self.start_line, 'finish': self.finish_line,
+ 'first': self.first_one, 'last': self.last_one,
'extra': self.extra_charge}
return block_str
-
+
def join(self, block):
self.start_line = min(self.start_line, block.start_line)
self.finish_line = max(self.finish_line, block.finish_line)
self.first_one = min(self.first_one, block.first_one)
self.last_one = max(self.last_one, block.last_one)
self.normalizeExtra(block)
-
+
def testUnification(self, block):
if self.first_one != block.first_one and self.last_one != block.last_one:
return False
@@ -160,7 +160,7 @@ Block ::::::::::::
(self.extra_charge > 0 and (block.extra_charge == BOTH or block.extra_charge == TOP)):
return True
return False
-
+
def getOverlappedBlocks(self, block_list):
overlapped_blocks = []
i = 0
@@ -173,7 +173,7 @@ Block ::::::::::::
overlapped_blocks.append(i)
i += 1
return overlapped_blocks
-
+
def getSurroundingBlocks(self, block_list):
i = 0
blocks_before = []
@@ -190,7 +190,7 @@ Block ::::::::::::
blocks_after.append(i)
i += 1
return blocks_before, blocks_after
-
+
def isContained(self, block_list):
i = 0
while i < len(block_list):
@@ -205,18 +205,18 @@ Block ::::::::::::
return False
class BlockRetriever:
-
+
def __init__(self, string_list):
self.string_list = string_list
self.original_string_list = self.string_list
self.text_blocks = []
-
+
def getFirstOne(self, s):
return s.find('1')
-
+
def getLastOne(self, s):
return s.rfind('1')
-
+
def unifyBlockLeft(self, start_line, tolerance = 3):
leftmost_one = self.getFirstOne(self.string_list[start_line])
if leftmost_one == -1:
@@ -235,7 +235,7 @@ class BlockRetriever:
break
current_line += 1
return (leftmost_one, current_line - 1)
-
+
def retrieveBlocks(self):
blocks = []
while not self.isBlank():
@@ -257,7 +257,7 @@ class BlockRetriever:
current_start_line = finish_line + 1
i += 1
return blocks
-
+
def getFirstColumnOfZeros(self, start_line, finish_line, first_one):
last_one = first_one
if last_one != -1:
@@ -266,7 +266,7 @@ class BlockRetriever:
if last_one > first_one:
last_one -= 1
return last_one
-
+
def __isZerosColumn(self, string_list, start_line, finish_line, col_index):
if not finish_line < len(string_list):
return False
@@ -278,7 +278,7 @@ class BlockRetriever:
return False
start_line += 1
return True
-
+
def resetBlockStringsWithZeros(self, block):
start_line = block.start_line
finish_line = block.finish_line
@@ -293,7 +293,7 @@ class BlockRetriever:
self.string_list[current_line] = current_string_line[0:first_one] + block_line_of_zeros + current_string_line[last_one + 1:len(current_string_line)]
current_line+=1
return block
-
+
def extendBlocksByBelongingSingles(self):
self.blocks = self.retrieveBlocks()
blocks = self.blocks
@@ -324,7 +324,7 @@ class BlockRetriever:
i = -1
i += 1
return blocks
-
+
def unifyBlocks(self, blocks):
i = 0
while i < len(blocks):
@@ -362,11 +362,11 @@ class BlockRetriever:
if self.getFirstOne(line) != -1:
return False
return True
-
+
def getAllBlocks(self):
blocks = self.extendBlocksByBelongingSingles()
blocks = self.unifyBlocks(blocks)
if OCRFEEDER_DEBUG:
for block in blocks:
debug(block)
- return blocks
\ No newline at end of file
+ return blocks
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]