3

I am trying to do image processing with Python. What I actually want to do is I have image with human and I need to indetify human faces or detect circle (basically human face). what I have done so far us

  1. I have done edge detection for image using sobel edge detection.

  2. Then I have converted image into binary image which saves binary image ad prints out array of the image which is 0 or 255 (Black and White)

  3. Now what I'm confused about after this what can I do to detect circle in image and print out how many human present in image.

  4. I am using still images so I am giving the input for the image

I am using Python, PIL, NumPy, and SciPy. I do not want to use OpenCV. I want to detect human face and count how many people are in image and then print out the number of people in image.

import numpy
import scipy
from scipy import ndimage

im = scipy.misc.imread('test5.jpg')
im = im.astype('int32')
dx = ndimage.sobel(im, 0)  # horizontal derivative
dy = ndimage.sobel(im, 1)  # vertical derivative
mag = numpy.hypot(dx, dy)  # magnitude
mag *= 255.0 / numpy.max(mag)  # normalize (Q&D)
scipy.misc.imsave('sobel.jpg', mag)

The code above its not mine I got it from online.

I have also asked this question in other forum as well.HERE

4

3 回答 3

3

你想要做的是可以使用 scipy、numpy 和 sklearn。

首先你要收集很多人脸的数据,然后是很多不是人脸的随机数据。

因此,假设您有 2000 张人脸图像和 10000 张非人脸图像。然后您需要将它们全部加载,标准化它们的大小和强度,然后将它们传递给 SVM 进行分类。人脸照片的标签应该是1,非人脸的标签应该是0。

images = [image1, image2, image3... imagen]
labels = [0 1 1 ... 0]

当你在上面构建了这个之后,你需要将它传递给一个 svm:

faceclassifier = SVC()
faceclassifier.fit(images, labels) 

在此处查看更多信息 http://scikit-learn.org/dev/modules/generated/sklearn.svm.SVC.html

然后在每个新的查询图像中获取所有带有滑动窗口的块,并将每个块通过 SVM。

如果 SVM 结果高,则将其分类为表示人脸的块,如果不是,则不是人脸。

一般来说,您无法使用图像处理技术构建准确的人脸检测器,您应该使用计算机视觉和机器学习。

于 2013-02-24T11:10:48.943 回答
1

好吧,您应该研究 Viola Jones 算法。opencv 库本身有一个很好的实现。这是目前用于检测图像中人脸的最佳算法之一。尽管当您倾向于制作深度架构时,会有更好的算法。

于 2015-09-06T05:46:47.063 回答
0

I agree with entropiece posted. Using computer vision and machine learning is the usual approach to problems like this.

However, if you still want to try and attempt using circle detection to this end, you might want to look into Circle Hough Transform. It's fairly straightforward to code, even from scratch if you don't want to use any other libraries.

于 2016-10-21T09:08:46.533 回答