How do you cut a face out of an image? - opencv

I have been given an image with rgb channels. I only want to see the persons face. How would I do that? Are neural nets used for this? If so, are there existing data files from neural nets that have already done the processing?

Since your questions is tagged with OpenCV, I will assume that you are looking for a solution within this library.
The first step is to find the faces. For this, use one of the cascade object detectors that are available: either the Viola-Jones one or the LBP one.
OpenCV comes with cascades trained for face detection for each of these detectors.
Then, it depends if getting a bounding box is enough or not.
If you need something more accurate, then you can:
[coarse face] use a skin color detector inside the face bounding box to get a finer face estimate, binarize the image and finally close the face shape using morphological filtering;
[fine face contour] use something like a grabcut procedure to get a pixel-accurate contour. You can initialize the grabcut with borders of the bounding box as background and center part of the bounding box as foreground.

Not really sure what you want to do, but you can use Haar Classifier for face detection.
From then on, it should be easy to only display the face. While there are available classifiers online, you can try training your own classifier should you have the time. I have done classifiers on hand, face, eyes before and it have an impressive result.
Should you need more help on training classifier, etc, just comment here, I will try my best to assist you.

Face detection functionality is also available in the Computer Vision System Toolbox for MATLAB in the form of the vision.CascadeObjectDetector object.

Related

Detect symbols written on a whiteboard using OpenCV

I'm trying to detect shapes written on a whiteboard with a black/blue/red/green marker. The shapes can be circles, rectangles or triangles. The image can be found at the bottom of this post.
I'm using OpenCV as the framework for the image recognition.
My first task is to research and list the different strategies that could be used for the detection. So far I have found the following:
1) Grayscale, Blur, Canny Edge, Contour detection, and then some logic to determine if the contours detected are shapes?
2) Haar training with different features for shapes
3) SVM classification
4) Grayscale, Blur, Canny Edge, Hough transformation and some sort of color segmentation?
Are there any other strategies that I have missed? Any newer articles or tested approaches? How would you do it?
One of the test pictures: https://drive.google.com/file/d/0B6Fm7aj1SzBlZWJFZm04czlmWWc/view?usp=sharing
UPDATE:
The first strategy seems to work the best, but is far from perfect. Issues arise when boxes are not closed, or when the whiteboard has a lot of noise. Haar training does not seems very effective because of the simple shapes to detect without many specific features. I have not tried CNN yet, but it seems most appropriate to image classification, and not so much to detect shapes in a larger image (but I'm not sure)
I think that the first option should work. You can use fourier descriptors in order to classify the segmented shapes.
http://www.isy.liu.se/cvl/edu/TSBB08/lectures/DBgrkX1.pdf
Also, maybe you can find something useful here:
http://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/
If you want to try a more challenging but modern approach, consider deep learning approach (I would start with CNN). There are many implementations available on the internet. Although it is probably an overkill for this specific project, it might help you in the future...

OpenCV: Refine Cascade Face Detection

I'm making system for emotion detection on Android mobile phone. I'm using OpenCV's Cascades (LBP's or Haars) to find face, eyes, mouth areas etc. What I have observed till now that accuracy isn't stable. There are situations where I can't find eye or I have "additional faces" in the background due to very slight change of light. What I wanted to ask is:
1) Is Haar Cascade more Accurate than LBP?
2) Is there any good method for increasing accuracy of detection? Like find face/eyes etc on binarized image, or use some edge detection filter, saturation, anything else?
you can try Microsoft API for face emotion detection ..i am trying in my project so..result is best..try this link
https://www.microsoft.com/cognitive-services/en-us/emotion-api
sometimes HAAR or LBP will not get a good enough result for a face detection system. if you want to get more good acc. i think you can try to using STASM
it base on opencv and using Haar to detect face and landmark. something others you can also try YOLO Face detection
if you want to build your own face detection system just base on Haar or LBP and make them get a good result, maybe you will need to using the LBP to find out the face faster and train a CNN model to get the last good result, it can make your system to detect faces in realtime. as i know, the SEETAFACE is using this way to make a realtime faces detection.

Haar Cascade vs Hog Detection

I have been working around with OpenCV for few days now and I have a project where I should detect cars and humans from the sky.
So here are my inputs:
A moving camera in the sky (embedded on a quadcopter) which is gonna capture frames.
A set of objects I should detect (humans and cars)
And here are my output:
A detection of those objects outlined by a rectangle or some contours
Based on that, my question is as follows: Which one between Haar Cascade and Hog Detection would you recommend to do so and why? Or any else?
Many thanks for your answers
HOG is usually better for human detection, than Haar. I have only experience in this so I thought I'd give some input on that. However, the limitation of HOG is that the human must be within a "perfect" area on the screen. Too close, it won't detect the human. Too far, it won't detect the human.
I have had better luck with HOG than Haar. Haar gave me too many false positives.
I have been trying to use HAAR to detect human, and it turns out to give too many false positives. I think HAAR is only suitable for face or eye detection.
since your camera is in the sky, the human is pretty small in the image and got a whole body shape. HOG would be a better choice.
You need to change scale factor and minimum neighbours in HAAR cascade which is not same for all the image. So it's better to use HOG.

OpenCV - Haar classifier for long objects with different angles

I have used Haar classifier with OpenCV before succesfully. Unfortunately it seems to work only on square objects and fixed angles (i.e. faces). However I need to find "long" (rectangular) objects which have different angles (see sample input image).
Is there a way to train Haar classifier to find such objects? All I can find are tutorials for face recognition. Any other alternative approches?
Haar classifiers are known to work with rigid object only. You need a classifier for each of the view. For example, the side-face classifier in OpenCV doesn't work as good as front-face classifer(due to the reason being, side face has more variation in yaw-pitch-roll than front face).
There is no perfect way of answering your question.
However, in your case whatever you are trying to classify (microbes I suppose) are overlapping on each other. Its a complex issue. But, you can isolate the region where microbes occur (not isolate each microbe like a face).
You can refer fingerprint segmentation techniques that are known to enhance the ridges on a fingerprint (here in your case its microbe edges) from the background and isolate the image.
Check "ridgesegmentation.m" in the following page:
http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/index.html

Iris detection with opencv

How can I detect irises in a face with opencv?
Have a look at this forum thread. There's some source code there to get you started, but be careful about using it directly -- the original author seemed to have problems compiling it.
Start with detecting circles - see cvHoughCircles - hint, eyes have a series of concentric circles.
OpenCV has Face Detection module which uses Haar Cascade. You can use the same method to detect Iris. You collect some iris images and make it as positive set and non iris images as negative set. The use the Haar Training module to train it.
Quick and dirty would be making an eye detection first with Haar filter, there are good model xml files shipped with opencv 2.4.2. Then you do some skin detection (in the HSV space rather than the rgb space) to identify the area of the eye in the middle, or circle search.
Also, projections, histogram-based decisions can be used once the eye area is cropped.

Resources