Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image processing using Python and SciPy

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

like image 237
user2096230 Avatar asked May 06 '26 16:05

user2096230


2 Answers

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.

like image 144
entropiece Avatar answered May 09 '26 05:05

entropiece


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.

like image 32
iec2011007 Avatar answered May 09 '26 07:05

iec2011007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!