I don't think there's something already written for what you are trying to accomplish (at least open source and in Python).
As for your second question, it depends on what you are trying to recognize. If the inputs can come from different sources -- e.g., different brands of playing cards with distinctive styles --, then you should probably use a machine learning-based algorithm (such as neural network or support vector machine [SVM]), in order to let it learn how to recognize unknown inputs. However, if the input is always the same in shape or style, then a simple image comparison algorithm will suffice (e.g., compare the pixels of the sliced upper-left corner with the pixels of each rank).
If you do decide to use a machine learning-based algorithm, I also think you don't need very complex features, as the suits and ranks don't really vary that much in shape or style, and you should be fine with using just the pixels of the upper left corner as features.
There's a toy OCR example here that you may find interesting. The lib that is used (LibSVM) also has a Python version, which I have used, and found very simple to work with.
Given the limited sample size (4 suits, 13 different values) I'd just try to match a reference image of the suit and value with a new input image. First find the bounding box of the incoming suit / value (the smallest box enclosing all non-white pixels), scale your reference pictures to match the size of that bounding box, and find the best "match" through pixel-wise absolute difference. The colour of the picture (i.e. red or black) will make this even easier.
It's not as robust, but you can look at the colours of 3 or 4 locations on the card so that if they are white or if they are a color, you can determine which card and suit it is. Obviously this won't work if you don't always have the same cards.
发布评论
评论(4)
我不认为已经为您想要完成的任务编写了一些东西(至少是开源的和用 Python 编写的)。
至于你的第二个问题,这取决于你想要认识什么。 如果输入可以来自不同的来源 - 例如,具有独特风格的不同品牌的扑克牌 - 那么您可能应该使用基于机器学习的算法(例如神经网络或支持向量机) [SVM]),以便让它学习如何识别未知输入。 但是,如果输入的形状或样式始终相同,则简单的图像比较算法就足够了(例如,将切片左上角的像素与每个等级的像素进行比较)。
如果您确实决定使用基于机器学习的算法,我也认为您不需要非常复杂的功能,因为花色和等级在形状或风格上并没有太大变化,并且您应该只使用左上角的像素作为特征。
此处有一个 OCR 玩具示例,您可以使用可能会觉得有趣。 使用的库(LibSVM)也有一个Python版本,我已经使用过,并且发现使用起来非常简单。
希望能帮助到你。
I don't think there's something already written for what you are trying to accomplish (at least open source and in Python).
As for your second question, it depends on what you are trying to recognize. If the inputs can come from different sources -- e.g., different brands of playing cards with distinctive styles --, then you should probably use a machine learning-based algorithm (such as neural network or support vector machine [SVM]), in order to let it learn how to recognize unknown inputs. However, if the input is always the same in shape or style, then a simple image comparison algorithm will suffice (e.g., compare the pixels of the sliced upper-left corner with the pixels of each rank).
If you do decide to use a machine learning-based algorithm, I also think you don't need very complex features, as the suits and ranks don't really vary that much in shape or style, and you should be fine with using just the pixels of the upper left corner as features.
There's a toy OCR example here that you may find interesting. The lib that is used (LibSVM) also has a Python version, which I have used, and found very simple to work with.
Hope it helps.
就我个人而言,我会选择机器学习路线。
Personally I would go the machine learning route with this one.
考虑到样本大小有限(4 种套装,13 个不同的值),我只是尝试将套装和值的参考图像与新的输入图像进行匹配。 首先找到传入的套装/值的边界框(包围所有非白色像素的最小框),缩放参考图片以匹配该边界框的大小,并通过像素级绝对差找到最佳“匹配”。 图片的颜色(即红色或黑色)将使这变得更加容易。
Given the limited sample size (4 suits, 13 different values) I'd just try to match a reference image of the suit and value with a new input image. First find the bounding box of the incoming suit / value (the smallest box enclosing all non-white pixels), scale your reference pictures to match the size of that bounding box, and find the best "match" through pixel-wise absolute difference. The colour of the picture (i.e. red or black) will make this even easier.
它不是那么强大,但您可以查看卡片上 3 或 4 个位置的颜色,这样如果它们是白色还是彩色,您就可以确定它是哪张卡片和花色。 显然,如果你不总是拥有相同的卡,这将不起作用。
It's not as robust, but you can look at the colours of 3 or 4 locations on the card so that if they are white or if they are a color, you can determine which card and suit it is. Obviously this won't work if you don't always have the same cards.