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

Donald Duck
  • 6,488
  • 18
  • 59
  • 79
user2096230
  • 57
  • 1
  • 5
  • 3
    you're going to regret that idea, NOT using opencv ;) – berak Feb 21 '13 at 17:09
  • i cant use opencv as my teacher strictly told me not to so no choice. :( @berak – user2096230 Feb 21 '13 at 17:11
  • What is your dataset like? Do you need to identify a face in a crowd, or do you need to recognize a face when it fills the frame? – David Marx Feb 22 '13 at 06:03
  • i need to recognise all faces in photo. whether its crowd or 1 person or 3 person. i need identify how many people are present in image. hope i made myself clear and not confusing you. @DavidMarx – user2096230 Feb 22 '13 at 10:26
  • Trying to detect faces by detecting circles is nearly a 100% guarantee that the method will fail completely. The fact that you don't use a certain library is completely fine, but this doesn't mean you cannot study the methods that are expected to work, and implement them. Viola-Jones and LBP are two methods that have been used for the task, and it always require a dataset for training/testing a classifier. – mmgp Feb 22 '13 at 14:10
  • it does not matter if i cant find all the faces in the image as long as few faces can be detected or something can be done it is ok. @mmgp – user2096230 Feb 22 '13 at 17:03
  • You are more likely to miss all the faces and detect a lot of non-faces. I really don't expect this approach to be any good, do you have any evidence (paper, working code, etc) that it works ? – mmgp Feb 22 '13 at 17:21
  • No i dont have anything like that my teacher told me to try doing this way and i know very basic numpy and other libs and i have so little time to learn in details as well :( @mmgp – user2096230 Feb 22 '13 at 17:31
  • You most probably can "force" it work for a specific group of images, but it cannot be generalized. Do you have such specific group of images do you expect this to work ? – mmgp Feb 22 '13 at 17:35
  • as i have to test if it works or not so minimum i have to try with 10-15 different types of images. its not specific images it can be any image of people. @mmgp – user2096230 Feb 22 '13 at 17:41
  • 10-15 different images is a very restricted set of images. – mmgp Feb 22 '13 at 17:46
  • i can use it more as well this is the minimum amount i am saying i have to use. i can take image form internet or anywhere it dnt matter which image it is as long as its image with people and i can count how many people are in image. and that dont have to 100% perfect as well. say if i can find 2 people in image which idealy has 5 people that would be fine as well. @mmgp – user2096230 Feb 22 '13 at 17:50

3 Answers3

3

What you want to do is doable with scipy, numpy and sklearn.

First you have to collect a lot of data of faces, and then a lot of random data that are not faces.

So lets say that you have 2000 images of faces, and 10000 non-face images. You need to then load them all, normalize their size and their intensities, and then pass them to an SVM for classification. The labels of the face photos should be 1, and the labels of the non faces should be 0.

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

When you have built this above, you need to pass it to an svm:

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

See more here http://scikit-learn.org/dev/modules/generated/sklearn.svm.SVC.html

Then get all blocks with a sliding window in each new query image, and pass each block through the SVM.

If the SVM result is high, classify it as a block that represents a face, if not then it is not a face.

In general, there is NO way you can build an accurate face detector with image processing techniques, you should use computer vision and machine learning.

entropiece
  • 379
  • 4
  • 10
1

Well you should look into Viola Jones algorithm. There is a nice implementation in the opencv library itself. This is one of the best algorithms out there for detecting faces in an image. Though there are better algorithms when you tend to make a deep architecture.

iec2011007
  • 1,630
  • 3
  • 20
  • 34
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.

mattbv
  • 21
  • 5