10瓶保龄球得分捕捉

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

我想使用 OCR 从投矛处的监视器捕获保龄球得分。我查看了这个数独解算器,因为我认为它非常相似 - 数字和网格对吗?很难找到水平线。有没有人有任何关于预处理此图像以使其更容易检测线条(或数字!)的提示。还有关于如何处理分割的任何提示(图像中一些 8 周围的橙色椭圆)?

到目前为止,我已经得到了得分区域的轮廓并裁剪了它。

import matplotlib
matplotlib.use('TkAgg')
from skimage import io
import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
from skimage.color import rgb2gray
# import pytesseract
from matplotlib.path import Path
from qhd import *


def polygonArea(poly):
    """
    Return area of an unclosed polygon.

    :see: https://stackoverflow.com/a/451482
    :param poly: (n,2)-array
    """
    # we need a plain list for the following operations
    if isinstance(poly, np.ndarray):
        poly = poly.tolist()
    segments = zip(poly, poly[1:] + [poly[0]])
    return 0.5 * abs(sum(x0*y1 - x1*y0
                         for ((x0, y0), (x1, y1)) in segments))

filename = 'good.jpg'
image = io.imread(filename)
image = rgb2gray(image)

# Find contours at a constant value of 0.8
contours = measure.find_contours(image, 0.4)

# Display the image and plot all contours found
fig, ax = plt.subplots()

c = 0
biggest = None
biggest_size = 0

for n, contour in enumerate(contours):
    curr_size = polygonArea(contour)
    if  curr_size > biggest_size:
        biggest = contour
        biggest_size = curr_size

biggest = qhull2D(biggest)


# Approximate that so we just get a rectangle.
biggest = measure.approximate_polygon(biggest, 500)

# vertices of the cropping polygon
yc = biggest[:,0]
xc = biggest[:,1]
xycrop = np.vstack((xc, yc)).T

# xy coordinates for each pixel in the image
nr, nc = image.shape
ygrid, xgrid = np.mgrid[:nr, :nc]
xypix = np.vstack((xgrid.ravel(), ygrid.ravel())).T

# construct a Path from the vertices
pth = Path(xycrop, closed=False)

# test which pixels fall within the path
mask = pth.contains_points(xypix)

# reshape to the same size as the image
mask = mask.reshape(image.shape)

# create a masked array
masked = np.ma.masked_array(image, ~mask)

# if you want to get rid of the blank space above and below the cropped
# region, use the min and max x, y values of the cropping polygon:

xmin, xmax = int(xc.min()), int(np.ceil(xc.max()))
ymin, ymax = int(yc.min()), int(np.ceil(yc.max()))
trimmed = masked[ymin:ymax, xmin:xmax]

plt.imshow(trimmed, cmap=plt.cm.gray), plt.title('trimmed')
plt.show()

https://i.stack.imgur.com/CGZOP.jpg 是分数显示方式的示例。

python opencv computer-vision ocr scikit-image
1个回答
0
投票

我没有答案,但我希望8年后你能找到解决方案?我正在做一个类似的保龄球项目,我想使用你想出的任何代码/人工智能。谢谢并抱歉!

© www.soinside.com 2019 - 2024. All rights reserved.