Fix AttributeError on self.width if Tesseract finds no OCR text

self.width remains undefined unless hOCR finds text.  It might not, if
a page contains only an image for example.

Full error message is:
AttributeError: ‘hocrTransform’ object has no attribute ‘width’
This commit is contained in:
Jim Barlow
2014-01-12 22:10:15 -08:00
parent bf02ee3bdc
commit 1d62ef27a2
+1
View File
@@ -115,6 +115,7 @@ class hocrTransform():
self.xmlns = matches.group(1)
# get dimension in pt (not pixel!!!!) of the OCRed image
self.width, self.height = None, None
for div in self.hocr.findall(".//%sdiv[@class='ocr_page']"%(self.xmlns)):
coords = self.element_coordinates(div)
self.width = self.px2pt(coords[2]-coords[0])