I try to run this code fragment. And I don't get any errors at compile time. But if I run the script. I get this errors:
File "c:\Users\engel\Documents\python\code\textFromImages.py", line 8, in <module>
class Text_from_image:
File "c:\Users\engel\Documents\python\code\textFromImages.py", line 47, in Text_from_image
print(filterAnanas())
TypeError: Text_from_image.filterAnanas() missing 1 required positional argument: 'self'
class Text_from_image:
#class variables:
apples_royal_gala = 'Appels Royal Gala 13kg 60/65 Generica PL Klasse I'
ananas_crownless = 'Ananas Crownless 14kg 10 Sweet CR Klasse I'
peen_waspeen = 'Peen Waspeen 14x1lkg 200-400 Generica BE Klasse I'
def __init__(self) :
pass
def make_pattern(substr):
return r"(?<=" + substr + r").*?(?P<number>[0-9,.]*)\n"
def get_text_from_image():
pdfFile = wi(
filename="C:\\Users\\engel\\Documents\\python\\docs\\fixedPDF.pdf", resolution=300)
text_factuur_verdi = []
image = pdfFile.convert('jpeg')
imageBlobs = []
for img in image.sequence:
imgPage = wi(image=img)
imageBlobs.append(imgPage.make_blob('jpeg'))
for imgBlob in imageBlobs:
image = Image.open(io.BytesIO(imgBlob))
text = pytesseract.image_to_string(image, lang='eng')
text_factuur_verdi.append(text)
return text_factuur_verdi
def filterAnanas(self):
self.get_text_from_image()
return re.findall(self.make_pattern(self.ananas_crownless), self.text_factuur_verdi[0])
if ananas_crownless:
print(filterAnanas())
So my question is how to fix this?