python - 有规则的数字识别

标签 python neural-network

我正在寻找从图像中提取和识别数字。 我读过很多有关数字识别的内容,但没有找到任何有关添加规则来选择我们感兴趣的数字的内容。

规则将“非常简单”,例如,我只想提取用蓝色笔包围的数字。

不要在这里等待整个解决方案,而是更多的研究轴或类似问题的链接。 Sample

我对神经网络非常熟悉,并打算在这方面使用神经网络。但我不知道如何仅过滤掉周围的数字。

这是图片的示例。在一张图片上对相同的架构进行多次成像。

最佳答案

我认为你有三种操作方式。也许您不需要走那么远!目前,我们只会查找已选择的一项。

情况 1:您可以尝试使用圆的霍夫变换来查找图像中存在的圆。

% Solution 1 (practically a perfect cicle, use hough circle transform to find circles)
im = imread('/image/L7cE1.png');
[centers, radii, metric] = imfindcircles(im, [10, 60]);
imshow(im); viscircles(centers, radii,'EdgeColor','r');

情况2:您可以在蓝色的空间中工作并消除非彩色来分割您感兴趣的区域(如果添加边距则可以正确工作)。

% Solution 2 (ALWAYS is blue, read only rgB channel and delete achromatic)
b = im(:, :, 3) & (std(double(im(:, :, :)), [], 3) > 5);
bw = imfill(b,'holes');
stats = regionprops('table', bw, 'Centroid', 'MajorAxisLength','MinorAxisLength')
imshow(im); viscircles(stats.Centroid, stats.MajorAxisLength / 2,'EdgeColor','r');

情况 3:您可以将正面案例和其他负面案例一起生成一个数据集。训练一个具有 10 个输出的神经网络,每个输出都指示是否有划掉(S 形输出)。这种类型模型的好处是您以后不应该进行 OCR。

import keras
from keras.layers import *
from keras.models import Model
from keras.losses import mean_squared_error
from keras.applications.mobilenet import MobileNet
def model():
    WIDTH, HEIGHT = 128, 128
    mobile_input = Input(shape=(WIDTH, HEIGHT, 3))
    alpha = 0.25 # 0.25, 0.5, 1
    shape = (1, 1, int(1024 * alpha))
    dropout = 0.1
    input_ = Input(shape=(WIDTH, HEIGHT, 3))
    mobile_model = MobileNet(input_shape=(WIDTH, HEIGHT, 3), 
                             alpha= alpha, 
                             include_top=False, 
                             dropout = dropout,
                             pooling='avg')
    base_model = mobile_model(mobile_input)
    x = Reshape(shape, name='reshape_1')(base_model)
    x_gen = Dropout(dropout, name='dropout')(x)
    x = Conv2D(10, (1, 1), padding='same')(x_gen)
    x = Activation('sigmoid')(x)
    output_detection = Reshape((10,), name='output_mark_detection')(x)

    """x = Conv2D(2 * 10, (1, 1), padding='same')(x_gen)
    x = Activation('sigmoid')(x)
    output_position = Reshape((2 * 10, ), name='output_mark_position')(x)
    output = Concatenate(axis=-1)([output_detection, output_position])
    """

    model = Model(name="mark_net", inputs=mobile_input, outputs=output_detection)

这取决于你的问题,第一个案例可以为你服务。如果有不同的光照、旋转、缩放等条件,我建议您直接进入神经网络,您可以创建许多“人工”示例:

  1. 您可以通过添加扭曲数据来生成人工数据集 圆圈(取一个正常的圆圈,随机应用 仿射变换,添加噪音,稍微改变蓝色, 线等)。
  2. 然后将随机圆圈粘贴到每个数字中,然后 生成数据集,指示标记了哪些数字。
  3. 一旦“停留在纸上”,您可以再次应用数据增强 让它看起来更真实。

关于python - 有规则的数字识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54178246/

相关文章:

python - 如何从 FastAPI 文档中隐藏 Pydantic 鉴别器字段

javascript - d3 js可以扩展多少

python - sklearn 的 MLPClassifier 的 Predict_proba() 函数输出总可能性不等于 1

matlab - 神经网络对测试数据的预测只有 50%

python - 制作 Python 批处理文件

python - 如何构建 Flask 用户应用程序?

python - 如何在我的 python 应用程序中保护我的 AWS 访问 ID 和 key

python - 使用权重文件离线加载keras resnet50模型失败

python - 广而深的tensorflow教程: Why do you test using only a batch of your evaluation dataset?

python - 神经网络可以学习|sin(x)|对于 [0,pi] 但不是 [0,2pi] 或 [0, 4pi]