It depends on how fast you need to be. If you can isolate the square of the letter and rotate it so that the sides of the square containing the letter are horizontal and vertical then I would suggest you:
convert the images to black/white (with the letter the one colour and the rest of the die the other
make a dataset of reference images of all letters in all four possible orientations (i.e. upright and rotated 90, 180 and 270 degrees)
use a template matching function such as cvMatchTemplate to find the best matching image from your dataset for each new image.
This will take a bit of time, so optimisations are possible, but I think it will get you a reasonable result. If getting them in a proper orientation is difficult you could also generate rotated versions of your new input on the fly and match those to your reference dataset.
If the letters have different scale then I can think of two options:
If orientation is not an issue (i.e. your boggle block detection can also put the block in the proper orientation) then you can use the boundingbox of the area that has the letter colour as rough indicator of the scale of the incoming picture, and scale that to be the same size as the boundingbox on your reference images (this might be different for each reference image)
If orientation is an issue then just add scaling as a parameter of your search space. So you search all rotations (0-360 degrees) and all reasonable sizes (you should probably be able to guess a reasonable range from the images you have).
您可以使用简单的 OCR,例如 Tesseract。它使用简单并且速度相当快。不过,你必须进行 4 次旋转(如@jilles de wit 的答案中所述)。
You can use a simple OCR like Tesseract. It is simple to use and is quite fast. You'll have to do the 4 rotations though (as mentioned in @jilles de wit's answer).
I made an iOS-app that does just this, based on OpenCV. It's called SnapSolve. I wrote a blog about how the detection works. Basically, I overlay all 26x4 possible letters + rotations on each shape, and see which letter overlaps most. A little tweak to this is to smooth the overlay image, to get rid of artefacts where letters almost overlap but not quite.
发布评论
评论(3)
这取决于您需要多快。
如果您可以隔离字母的正方形并旋转它,以便包含字母的正方形的边是水平和垂直的,那么我建议您:
这将需要一些时间 。时间,所以优化是可能的,但我认为这会给你一个合理的结果。
如果让它们处于正确的方向很困难,您还可以动态生成新输入的旋转版本,并将其与您的参考数据集进行匹配。
如果字母具有不同的比例,那么我可以想到两个选项:
It depends on how fast you need to be.
If you can isolate the square of the letter and rotate it so that the sides of the square containing the letter are horizontal and vertical then I would suggest you:
This will take a bit of time, so optimisations are possible, but I think it will get you a reasonable result.
If getting them in a proper orientation is difficult you could also generate rotated versions of your new input on the fly and match those to your reference dataset.
If the letters have different scale then I can think of two options:
您可以使用简单的 OCR,例如 Tesseract。它使用简单并且速度相当快。不过,你必须进行 4 次旋转(如@jilles de wit 的答案中所述)。
You can use a simple OCR like Tesseract. It is simple to use and is quite fast. You'll have to do the 4 rotations though (as mentioned in @jilles de wit's answer).
我基于 OpenCV 制作了一个 iOS 应用程序来完成此任务。它称为 SnapSolve。我写了一篇关于检测工作原理的博客。
基本上,我在每个形状上覆盖所有 26x4 可能的字母 + 旋转,然后查看哪个字母重叠最多。对此进行一点调整是平滑叠加图像,消除字母几乎重叠但不完全重叠的伪影。
I made an iOS-app that does just this, based on OpenCV. It's called SnapSolve. I wrote a blog about how the detection works.
Basically, I overlay all 26x4 possible letters + rotations on each shape, and see which letter overlaps most. A little tweak to this is to smooth the overlay image, to get rid of artefacts where letters almost overlap but not quite.