首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带规则的数字识别

带规则的数字识别
EN

Stack Overflow用户
提问于 2019-01-14 08:54:20
回答 2查看 89关注 0票数 2

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

规则将是“相当简单的”,例如,我只想提取被蓝色钢笔包围的数字。

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

我非常熟悉神经网络,并打算在这方面使用神经网络。但我看不出如何只过滤掉被包围的数字。

这是一张照片的样本。在图片上显示相同的架构,但几次。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-14 22:51:41

我想你有三种操作方式。也许你不需要走那么远!就目前而言,我们只会寻找哪一个被选中。

案例1:,您可以尝试对圆圈使用hough变换来查找图像中的圆圈。

代码语言:javascript
复制
% Solution 1 (practically a perfect cicle, use hough circle transform to find circles)
im = imread('https://i.stack.imgur.com/L7cE1.png');
[centers, radii, metric] = imfindcircles(im, [10, 60]);
imshow(im); viscircles(centers, radii,'EdgeColor','r');

案例2:,您可以在蓝色的空间中工作,并消除消色差的颜色来分割您感兴趣的区域(如果添加边距,您可以正确地工作)。

代码语言:javascript
复制
% 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个输出的神经网络,如果有或没有划出(乙状结肠输出),每一个输出都表示输出。这种类型的模型的好处是以后不应该做OCR。

代码语言:javascript
复制
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. 一旦“卡在纸上”,您可以再次应用数据增强,以使它看起来更真实。
票数 2
EN

Stack Overflow用户

发布于 2019-01-14 11:12:51

你可以把这个问题分解成两个简单的子问题:你可以训练第一个神经网络来识别圆圈并将它们隔离开来。一旦你这样做了,你就可以训练第二个神经网络来识别你所隔离的部分中的数字。希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54178246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档