简体   繁体   中英

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM