def Spaces(image=None):
PrintGood('This returns the number of spaces in a specific image or images')
if isinstance(image, list) == False:
image = PromptList('Which image/images to Scan: ', image)
for image in image:
image = Image.open(image)
with PyTessBaseAPI() as api:
api.SetImage(image)
boxes = api.GetComponentImages(RIL.TEXTLINE, True)
Spaces = 0
for i, (im, box, _, _) in enumerate(boxes):
im.save('saving{}.jpg'.format(i))
api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
ocrResult = api.GetUTF8Text()
conf = api.MeanTextConf()
text = str(ocrResult).replace('\n', '').split(' ')
Spaces = len(text) + Spaces
return int(Spaces)
评论列表
文章目录