main.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Nightchord 作者: theriley106 项目源码 文件源码
def genLines(image=None):
    PrintGood('This is going to return OCR on either a list of images or full images')
    if isinstance(image, list) == False:
        image = PromptList('Which image/images to OCR: ', image)
    Found = []
    for image in image:
        image = Image.open(image)
        with PyTessBaseAPI() as api:
            api.SetImage(image)
            boxes = api.GetComponentImages(RIL.TEXTLINE, True)
            print 'Found {} textline image components.'.format(len(boxes))
            for i, (im, box, _, _) in enumerate(boxes):
                # im is a PIL image object
                # box is a dict with x, y, w and h keys
                api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
                ocrResult = api.GetUTF8Text().split(' ')
                conf = api.MeanTextConf()
                ocrResult = [word.strip() for word in ocrResult]
                Found.append(ocrResult)
                print (u"Box[{0}]: x={x}, y={y}, w={w}, h={h}, "
                       "confidence: {1}, text: {2}").format(i, conf, ocrResult, **box)
    return Found
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号