Bootstrap SomeTools Icon
返回
from PIL import Image
from cnocr import CnOcr

# 打开原图并裁剪
image = Image.open('img/test001.png')
select_name = "Nic"
# 裁剪区域
crop_area = (0, 603, 1211, 2526)
cropped_image = image.crop(crop_area)

# OCR识别获取数据
ocr = CnOcr()  # 使用默认OCR设置
out = ocr.ocr(cropped_image)
for text_cl in out:
    if select_name in text_cl["text"]:
        point_data = text_cl["position"]

x_point = (point_data[0][0] + point_data[2][0]) // 2
y_point = (point_data[0][1] + point_data[2][1]) // 2

# 缩放回原图中的坐标
x_abs = int(x_point + crop_area[0])
y_abs = int(y_point + crop_area[1])
print("原图中的绝对坐标:", x_abs, y_abs)