如何从图像中提取数字?

问题描述 投票:0回答:0

我有这张图片

我想将图片的文字颜色转换成相同的颜色,然后从图片中提取数字作为字符串。

这是我到目前为止所做的代码

import numpy as np
import cv2
import matplotlib.pyplot as plt


def downloadImage(URL):
    """Downloads the image on the URL, and convers to cv2 BGR format"""
    from io import BytesIO
    from PIL import Image as PIL_Image
    import requests

    response = requests.get(URL)
    image = PIL_Image.open(BytesIO(response.content))
    return cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)


URL = "https://i.imgur.com/prvJaK3.jpg"

# Read image
colorImage = downloadImage(URL)

RED, GREEN, BLUE = 0, 1, 2
# Filter image with much of GREEN, and little of RED and BLUE
greenImage = (
      (colorImage[:, :, RED] < 50)
    & (colorImage[:, :, GREEN] > 100)
    & (colorImage[:, :, BLUE] < 50)
)

blackImage = (
      (colorImage[:, :, RED] < 60)
    & (colorImage[:, :, GREEN] < 100)
    & (colorImage[:, :, BLUE] < 60)
)

plt.imshow(blackImage)
plt.show()

这样返回

我如何转换它以便每个数字都是相同的文本颜色并且我可以将它打印为图像到字符串?

python python-3.x image-processing python-imaging-library image-conversion
© www.soinside.com 2019 - 2024. All rights reserved.