Detecting faces that are looking into the webcam - java

I'm currently doing a face detection in Java/JavaCV.
So far I've been experimenting with the code.
I'm using this face cascade = haarcascade_frontalface_alt_tree.xml
I've got this code below for Detecting largest face found in the webcam
CvSeq faces = cvHaarDetectObjects(img, classifier, storage, 1.1, 1,
CV_HAAR_DO_ROUGH_SEARCH|CV_HAAR_FIND_BIGGEST_OBJECT);
My first question is:
Since this is only detecting one face - the largest face found in the webcam
is this the correct way to do it to detect multiple faces?
CvSeq faces = cvHaarDetectObjects(img, classifier, storage, 1.1, 1, CV_HAAR_DO_CANNY_PRUNING);
My second question is:
Is it possible to detect faces that are only looking into the webcam? and those that are not looking into the wbecam?
So the it will detect faces but I want to set some sort of scores - so let's say 1 is for faces that are looking into the webcam and 2 - for faces that are looking away from the webcam? How do I proceed to do this?
Thank you.

If a person looks directly, his/her eye should be perpendicular(if he/she doesn't have an eye problem :P).
This theory suggests, pupil and iris should be circular and not elliptical if a person looks directly.
Please note that I meant by the visible part of pupil and iris only.

Most face detection lib are trained toward people facing the camera since this isa major constraint for face recognition. This being said, Haar cascade can be trained also to detect profile or even focusing on eyes and nose (ie part of face).
I didn't use javaCV myself but tested openIMAJ (which rocks for me!) which can reuse openCV configuration file (as far as I understood). In the source of their face detection library, you will find models for profile and eye detection.

Related

OpenCV applying filters to specific place in image

Hello I am using OpenCV for Java and want to blur faces from image, but I keep failing to apply it only for face. How can I do it?
Your question is too general. What basically needs to be done is to run a face detection algorithm (google for face detection opencv), extract the rectangle of pixels depicting the face using cv::rect, blur them and replace the original pixels. I suggest you read about face detection (try to understand the main ideas regardless of openCV), read some tutorials on implementation and then, if you need assistance, write a more specific question here and people are sure to answer you.

Face Features Detection - corner of eyes, eyebrows

I am creating basic emotion detection system for mobile phone with usage of OpenCV4Android. My system is already capable of finding mouth and doing some preprocessing. I have nice results of getting face objects from Canny:
Examplary Face1: https://dl.dropboxusercontent.com/u/108321090/FACE%20%282%29.png
Examplary Face2: https://dl.dropboxusercontent.com/u/108321090/FACE%20%281%29.png
Red rectangles are areas found by cascades. I have those saved as Mat objects.
Blue dots are points I need to find. Problem is, that I have both eyebrows and eyes on the same segment.
Additionaly there are situations in which eyebrows are directly connected to eyes (in some emotion states). It's hard to access some points. I have also normal images (of course) and tresholded ones which are also interesting for eyebrow shapes - but I lose some other objects (mouth - well that one doesn't matter cuz its already done, eyes) due to bad light, well eyebrows are always well visible. Of course I could change tresholding a bit, cuz I dont need it in finding other features. Like I said mouths is done well. Eyes/Eyebrows left.
Examplary Face3: https://dl.dropboxusercontent.com/u/108321090/Screenshot_2014-01-17-01-33-14.png
Examplary Face4: https://dl.dropboxusercontent.com/u/108321090/Screenshot_2014-01-17-01-26-33.png
Examplary Face5 (a bit problematic, eyes gone, but if I treshold them localy not globaly its fine) https://dl.dropboxusercontent.com/u/108321090/Screenshot_2014-03-05-01-30-48.png
Exampalary Face6 (eyebrows conencted to eyes) https://dl.dropboxusercontent.com/u/108321090/Screenshot_2014-03-05-01-28-21.png
I want to ask you if you could provide me with any materials/ideas connected to detection of eye, and eyebrows action units.
if you can locate an eye/eye-brow unit you can probably just track it and relate emotions to the relative motion there rather than trying to separate eyes from eye-brows. Your first two exemplary faces are gradients while the rest are thresholded grey tones. I would rather use gradients since grey tones are affected by lighting and shadows.
I would also avoid using Canny edge detector since it is a highly non-linear and non-stable operator for matching sequential frames and hence for motion detection. I would rather use a simpler Sobel and some kind of motion detection but only after tracking subtracts a global head motion.
The interesting work on emotion detection was done based on Kinect and it really works though it requires a bit of offline training, see faceShift. A good test for right processing (before mapping features to emotions) is trying to move the model of the face in sync with target face - some kind of virtual avatar.

Poor Performance with OpenCV 2.4.8 face detection

I installed the OpenCV 2.4.8 Java API to play with the face detection example that is given in the tutorial.
In the example, lbpcascade_frontalface.xml -which is a CascadeClassifier- works OK in detecting the female face image (lena.png) that they provide. However, when I tried it on this random image from the web, the classifier produced the following image, missing 4 obvious(!) faces:
I am quite disappointed because I expected this (with the clear contrasts) to be a very easy image for detecting faces.
1) Coding in Java, is it possible to improve this classifier to detect all faces in this picture? Or do I need C++ for this?
2) I looked at OpenCV's CascadeClassification web page and saw taht it is possible to train your own classifier. But the instructions are in C++. Has anyone done this using Java or is it only doable in C++?
The training is not related to any programming language.
http://docs.opencv.org/doc/user_guide/ug_traincascade.html
You need only to use two already written programs included in the opencv library: createsamples and traincascade. You can use Haar and LBP features too, but the Haar features are slightly better for face detection. (And by the way: don't use haartraining).
I have saved your image and this c++ code finds the missing 4 faces as well as all the others (note the different Haar cascade and the minimum size):
Mat im1 = imread("JuVIA.png", CV_LOAD_IMAGE_COLOR);
vector<Rect> faces;
CascadeClassifier cascade( "C:/local/opencv249/sources/data/haarcascades/haarcascade_frontalface_alt2.xml" );
cascade.detectMultiScale( im1, faces, 1.1, 2, 0| CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++ )
cv::rectangle( im1, *r, CV_RGB(255,0,0) );
imshow("in", im1);
imwrite( "miss4.png", im1);
waitKey();
It is because the faceDetector the tutorial chose to use is lbpcascade_frontalface.xml which is not good enough, at least couldn't detect all the faces in the picture you used.
You may change to use haarcascade_frontalface_alt.xml under opencv-2.4.8\sources\data\haarcascades folder. Then all faces would be detected.
Here following is the result:, more details please refer to:http://www.pkuaas.org/?uid-1140-action-viewspace-itemid-3224

Ellipse detection with OpenCV

I would like to detect ellipses with OpenCV for Android, using the Tutorial 2-Basic included with OpenCV 2.4.1 package as a starting point. Note that my ellipse would be a perfect-photoshop one.
From what I understand, using the "HoughCircles" will only find perfect (or so) circles, thus leaving ellipses out.
Any help would be much appreciated as I am a total beginner at OpenCV
This is what I've tried so far
case Sample2NativeCamera.VIEW_MODE_CANNY: (ignore the Canny mode...)
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.HoughCircles(mGray, mCircles, Imgproc.CV_HOUGH_GRADIENT, 1, 20);
Log.d("Ellipse Points", " X " + mCircles.get(1,1)[0] + mCircles.get(1, 1)[1]);
break;
If you think any more info could be useful, please let me know.
One possible solution to your problem is similar to this thread Detection of coins (and fit ellipses) on an image .
You should take a look a opencv's function fitEllipse.
The parameters used in HoughCircles play a fundamental role. HoughCircles will detect not just perfect, but also near-perfect circles (ellipses). I suggest you check this examples:
How to detect circles (coins) in a photo
Simple object detection using OpenCV
OpenCV dot target detection
Reshaping noisy coin into a circle form
And this answer has a decent collection of references.
If you already have an idea of the sizes of the ellipses that you're looking for, then try the following steps:
Find Canny edges in the image
Use a sliding window, the size of which is the maximum length of the major axis of ellipses you're looking for.
Within the window, collect all edge pixels, pick 6 pixels randomly and use linear least squares to fit an ellipse in the general form.
Repeat the above step in a RANSAC like procedure.
If there are enough inliers, you have an ellipse.

Image matching using edge detection

I am doing my final year Mca and my topic is image matching using edge detection.
I have an Image at hand where the subject is not smiling, and two other images.
Bigger image containing the image at hand as a part of the image
Same as the image at hand with (some modification like smiling)
Now I want to check for presence in the first case, matching in the second case.
My approach:
I will find edges for all the given images-to reduce the amount of data to check.
I'm stuck on how to proceed. Any suggestions are extremely appreciated.
I have been Java user for years and I can do virtually anything, but ... as I found Mathematica about 2 years ago, I really started to love Mathematica. This is kind of problem I would use Mathematica to solve.
Just take a look at image processing reference.
Example of ImageCorrelate function:
CVOnline is a great source of computer vision algorithms. The section on edge detection can probably point you in the right direction.

Categories