我有4张小图片。在
有数字6、16、9和9。我用我的模板比较图片和数字,只有30个变体[0-30]。图片-截图是。数字出现在正方形的不同位置(例如,9在左角,9在右角)。在
我使用两种方法:计算白色像素的数量。在
original = cv2.imread('im/16.png')
sought = [254,254,254]
result = np.count_nonzero(np.all(original==sought,axis=2))
这种方法总是有效的,除了6和9。在这种情况下,白色像素的数量是相等的。在
第二种方法:获取图像上所有像素的位置,并将数据与其他图像进行比较:
^{pr2}$这个方法帮我区分6和9,但是!在两张不同角有9的图像中,它也能识别出不同之处。在
我希望我的代码能识别每个数字,而不是在图像的左右两侧看到一个数字之间的差异。在
在
opencv
中,您可以在6
和9
上训练一个分类器,基于Haar特征的级联分类器,用于对象检测(https://docs.opencv.org/3.4/d5/d54/group__objdetect.html,https://docs.opencv.org/3.4/dc/d88/tutorial_traincascade.html)示例代码在i.e.https://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html
我不知道这是否是一个任务,如果你被固定到opencv,如果不是你可以使用神经网络,cf章节隧道视觉的https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721或https://towardsdatascience.com/convnets-series-spatial-transformer-networks-cff47565ae81,但是对于这个问题,空间变换器网络有点过于复杂
您可以找到许多关于OCR的论文和软件,因为它在许多应用程序中得到了广泛的应用。我想用numpy和opencv为您的问题提供一个非常简单的解决方案,这样就可以解决问题了。在
我们要做的是:
代码:
函数,它将返回给定图像中的数字数组:
^{pr2}$获取数字
将第一张图片中的数字“9”和最后一张图片中的数字“6”放入数字银行。然后浏览我们在图3中找到的每个数字,并将其与我们的数字银行进行比较。如果分数低于0.9,则不匹配。在
最终结果将是“?”对于图3中的第一个数字,因为我们的银行中没有数字“1”,第二个结果将是“6”,得分为0.97。在
TLDR:我做了一个算法,从你的图像中分离出数字,并对这些数字进行比较。最佳匹配将打印出来。在
相关问题 更多 >
编程相关推荐