获取图片中文字坐标

tesseract环境已经搭建好情况下,获取图片中文字坐标

# -*- coding: utf-8 -*-
"""
根据图片取得文字坐标,需要注意图片识别坐标的原点在左下角(不是我们平时的左个角)
"""

import os


def recognition_img_txt(imgName):
    """
    将图片中文件识别出来

    """
    if os.path.isfile(imgName):
        os.system('/usr/local/bin/tesseract {} out -l chi_sim makebox'.format(imgName))
        print("输出坐标文件 out.box")
    else:
        print("{} not found.format(imgName)")


def get_position(str, imgName):
    """
    根据文字获取需要点击坐标 
    """
    recognition_img_txt(imgName)
    list = []
    if os.path.isfile('out.box'):
        with open('out.box') as f:
            for line in f:
                if line.split()[0] in str:
                    list.append(line.split())
    return list

猜你喜欢

转载自blog.csdn.net/u012700515/article/details/80403673