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

12
  • 3
    you're going to regret that idea, NOT using opencv ;) Commented Feb 21, 2013 at 17:09
  • i cant use opencv as my teacher strictly told me not to so no choice. :( @berak Commented Feb 21, 2013 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? Commented Feb 22, 2013 at 6: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 Commented Feb 22, 2013 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. Commented Feb 22, 2013 at 14:10

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.