python图像识别 [英] python image recognition
问题描述
我想做的是一个简单应用的图像识别:
what I want to do is a image recognition for a simple app:
- 给定图像 (500 x 500) 像素(1 种颜色背景)
- 图片将只有 1 个 (50x50) 像素的几何图形(三角形或正方形或 smaleyface :)).
- python 会识别图形并显示几何图形.
有链接吗?任何提示?任何API?谢谢:)
any links? any hints? any API? thxs :)
推荐答案
典型的python工具链是:
- 使用PIL 阅读您的图片
- 将它们转换为 Numpy 数组
- 使用 Scipy 的图像过滤器 (线性和排名,morphological) 来实施您的解决方案
- read your images with with PIL
- transform them into Numpy arrays
- use Scipy's image filters (linear and rank, morphological) to implement your solution
至于区分形状,我会通过查看背景的形状来获得它的轮廓.然后我会使用 角点检测 算法(例如 Harris)来检测角点的数量.一个三角形有 3 个角,一个正方形有 4 个,笑脸没有.这是一个 python 使用 Scipy 实现 Harris 角点检测一>.
As far differentiating the shapes, I would obtain its silhouette by looking at the shape of the background. I would then detect the number of corners using a corner detection algorithm (e.g. Harris). A triangle has 3 corners, a square 4, and a smiley none. Here's a python implementation of the Harris corner detection with Scipy.
正如您在评论中提到的,博客文章没有提供生成算法所需的高斯核的函数.这是 Scipy Cookbook(顺便说一句,很棒的资源)中的此类函数的示例:
As you mention in the comments, the blog post didn't present the function that produces a gaussian kernel needed in the algorithm. Here's an example of a such a function from the Scipy Cookbook (great resource btw):
def gauss_kern(size, sizey=None):
""" Returns a normalized 2D gauss kernel array for convolutions """
size = int(size)
if not sizey:
sizey = size
else:
sizey = int(sizey)
x, y = mgrid[-size:size+1, -sizey:sizey+1]
g = exp(-(x**2/float(size)+y**2/float(sizey)))
return g / g.sum()
这篇关于python图像识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!