Skip to content

Commit ca71a8a

Browse files
IlyaIlya
Ilya
authored and
Ilya
committed
Face Detection
1 parent 8fa7b06 commit ca71a8a

32 files changed

+369
-172
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
/nbproject/private/
1+
/nbproject/private/
2+
/build/
3+
/dist/

lib/artoolkitplus-windows-x86_64.jar

150 KB
Binary file not shown.

lib/artoolkitplus.jar

23.5 KB
Binary file not shown.

lib/ffmpeg-windows-x86_64.jar

15.6 MB
Binary file not shown.

lib/ffmpeg.jar

230 KB
Binary file not shown.

lib/flandmark-windows-x86_64.jar

38.8 KB
Binary file not shown.

lib/flandmark.jar

11.5 KB
Binary file not shown.

lib/flycapture-windows-x86_64.jar

227 KB
Binary file not shown.

lib/flycapture.jar

138 KB
Binary file not shown.

lib/javacpp.jar

246 KB
Binary file not shown.

lib/javacv.jar

358 KB
Binary file not shown.

lib/libfreenect-windows-x86_64.jar

187 KB
Binary file not shown.

lib/libfreenect.jar

21.5 KB
Binary file not shown.

lib/opencv-windows-x86_64.jar

8.41 MB
Binary file not shown.

lib/opencv.jar

602 KB
Binary file not shown.

lib/videoinput-windows-x86_64.jar

44 KB
Binary file not shown.

lib/videoinput.jar

15.1 KB
Binary file not shown.

lib/xstream-1.4.8.jar

-526 KB
Binary file not shown.

nbproject/project.properties

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
annotation.processing.enabled=true
22
annotation.processing.enabled.in.editor=false
3-
annotation.processing.processor.options=
43
annotation.processing.processors.list=
54
annotation.processing.run.all.processors=true
65
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
6+
application.title=EmotionChecker
7+
application.vendor=Ilya
78
build.classes.dir=${build.dir}/classes
89
build.classes.excludes=**/*.java,**/*.form
910
# This directory is removed when the project is cleaned:
@@ -26,14 +27,31 @@ dist.archive.excludes=
2627
dist.dir=dist
2728
dist.jar=${dist.dir}/EmotionChecker.jar
2829
dist.javadoc.dir=${dist.dir}/javadoc
30+
endorsed.classpath=
2931
excludes=
30-
file.reference.jdom-1.0.jar=lib\\jdom-1.0.jar
31-
file.reference.xstream-1.4.8.jar=H:\\Education\\Sem 9\\MISOI\\FaceChecker\\lib\\xstream-1.4.8.jar
32+
file.reference.artoolkitplus.jar=lib/artoolkitplus.jar
33+
file.reference.ffmpeg.jar=lib/ffmpeg.jar
34+
file.reference.flandmark.jar=lib/flandmark.jar
35+
file.reference.flycapture.jar=lib/flycapture.jar
36+
file.reference.javacpp.jar=lib/javacpp.jar
37+
file.reference.javacv.jar=lib/javacv.jar
38+
file.reference.jdom-1.0.jar=lib/jdom-1.0.jar
39+
file.reference.libfreenect.jar=lib/libfreenect.jar
40+
file.reference.opencv.jar=lib/opencv.jar
41+
file.reference.videoinput.jar=lib/videoinput.jar
3242
includes=**
3343
jar.compress=false
3444
javac.classpath=\
35-
${file.reference.xstream-1.4.8.jar}:\
36-
${file.reference.jdom-1.0.jar}
45+
${file.reference.artoolkitplus.jar}:\
46+
${file.reference.ffmpeg.jar}:\
47+
${file.reference.flandmark.jar}:\
48+
${file.reference.flycapture.jar}:\
49+
${file.reference.javacpp.jar}:\
50+
${file.reference.javacv.jar}:\
51+
${file.reference.jdom-1.0.jar}:\
52+
${file.reference.libfreenect.jar}:\
53+
${file.reference.opencv.jar}:\
54+
${file.reference.videoinput.jar}
3755
# Space-separated list of extra javac options
3856
javac.compilerargs=
3957
javac.deprecation=false
@@ -57,7 +75,7 @@ javadoc.splitindex=true
5775
javadoc.use=true
5876
javadoc.version=false
5977
javadoc.windowtitle=
60-
main.class=
78+
main.class=com.siv.ui.CameraFrame
6179
manifest.file=manifest.mf
6280
meta.inf.dir=${src.dir}/META-INF
6381
mkdist.disabled=false

opencv_java300.dll

23.8 MB
Binary file not shown.

src/com/siv/constant/Constants.java

-28
This file was deleted.

src/com/siv/detecton/Detector.java

+4-17
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,20 @@
1313
import java.util.List;
1414
import java.util.Iterator;
1515
import java.util.Scanner;
16-
import javax.imageio.ImageIO;
1716

1817
public class Detector {
1918

20-
/**
21-
* The list of classifiers that the test image should pass to be considered
22-
* as an image.
23-
*/
2419
List<Stage> stages;
2520
Point size;
2621

27-
/**
28-
* Detector constructor. Builds, from a XML file, the corresponding Haar
29-
* cascade.
30-
*
31-
* @param filename The XML file (generated by OpenCV) describing the Haar
32-
* cascade.
33-
* @throws java.io.FileNotFoundException
34-
*/
3522
public Detector(String filename) throws java.io.FileNotFoundException {
3623
this(new FileInputStream(filename));
3724
}
3825

3926
public Detector(InputStream input) {
4027
org.jdom.Document document = null;
4128
Element racine;
42-
stages = new LinkedList<Stage>();
29+
stages = new LinkedList<>();
4330
SAXBuilder sxb = new SAXBuilder();
4431
try {
4532
//On cr�e un nouveau document JDOM avec en argument le fichier XML
@@ -139,7 +126,7 @@ public List<java.awt.Rectangle> getFaces(int[][] array, float baseScale, float s
139126
image.setRGB(x, y, array[y][x]);
140127
}
141128
}
142-
List<Rectangle> ret = new ArrayList<Rectangle>();
129+
List<Rectangle> ret = new ArrayList<>();
143130
int width = image.getWidth();
144131
int height = image.getHeight();
145132
float maxScale = (Math.min((width + 0.f) / size.x, (height + 0.0f) / size.y));
@@ -256,8 +243,8 @@ public int[][] getIntegralCanny(int[][] grayImage) {
256243
return canny;
257244
}
258245

259-
public List<java.awt.Rectangle> merge(List<java.awt.Rectangle> rects, int min_neighbors) {
260-
List<java.awt.Rectangle> retour = new LinkedList<java.awt.Rectangle>();
246+
public List<Rectangle> merge(List<Rectangle> rects, int min_neighbors) {
247+
List<Rectangle> retour = new ArrayList<>();
261248
int[] ret = new int[rects.size()];
262249
int nb_classes = 0;
263250
for (int i = 0; i < rects.size(); i++) {

src/com/siv/filter/CannyFilter.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.siv.filter;
2+
3+
/**
4+
*
5+
* @author Ilya
6+
*/
7+
public class CannyFilter implements Filter{
8+
9+
@Override
10+
public FilterType getType() {
11+
return FilterType.CANNY;
12+
}
13+
14+
@Override
15+
public int[][] applyFilter(int[][] image) {
16+
return image;
17+
}
18+
19+
}

src/com/siv/filter/FaceFilter.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,25 @@
1212
*
1313
* @author Ilya
1414
*/
15-
public class FaceFilter extends Filter {
15+
public class FaceFilter implements Filter {
1616

1717
@Override
1818
public int[][] applyFilter(int[][] image) {
1919
try {
2020
Detector d = new Detector("resources\\haarcascade_frontalface_default.xml");
21-
List<Rectangle> faces = d.getFaces(image, 1, 1.25f, 0.1f, 1, true);
21+
List<Rectangle> faces = d.getFaces(image, 1, 1.25f, 0.1f, 1, false);
2222
for (Rectangle r : faces) {
2323
for (int x = r.x; x <= r.x + r.width; x++) {
24-
for (int y = r.y; y< r.y + r.height; y++) {
25-
image[y][x] = Color.WHITE.getRGB();
26-
}
24+
image[r.y][x] = Color.black.getRGB();
25+
}
26+
for (int x = r.x; x <= r.x + r.width; x++) {
27+
image[r.y + r.height][x] = Color.black.getRGB();
28+
}
29+
for (int y = r.y; y <= r.y + r.height; y++) {
30+
image[y][r.x] = Color.black.getRGB();
31+
}
32+
for (int y = r.y; y <= r.y + r.height; y++) {
33+
image[y][r.x + r.width] = Color.black.getRGB();
2734
}
2835
}
2936
} catch (FileNotFoundException ex) {
@@ -32,4 +39,9 @@ public int[][] applyFilter(int[][] image) {
3239
return image;
3340
}
3441

42+
@Override
43+
public FilterType getType() {
44+
return FilterType.FACE_DETECTION;
45+
}
46+
3547
}

src/com/siv/filter/Filter.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@
44
*
55
* @author Ilya
66
*/
7-
public abstract class Filter {
8-
9-
private FilterType type;
10-
11-
public FilterType getType() {
12-
return type;
13-
}
7+
public interface Filter {
148

15-
public void setType(FilterType type) {
16-
this.type = type;
17-
}
9+
FilterType getType();
1810

19-
public abstract int[][] applyFilter(int[][] image);
11+
int[][] applyFilter(int[][] image);
2012

2113
}

src/com/siv/filter/FilterManager.java

+80-9
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,89 @@
1111
public class FilterManager {
1212

1313
private final ReentrantLock lock = new ReentrantLock();
14-
private HashMap<FilterType, Filter> filters = new HashMap<>();
15-
14+
private final HashMap<FilterType, Filter> filters = new HashMap<>();
15+
private Filter faceFilter;
16+
1617
public BufferedImage applyFilters(BufferedImage image) {
17-
return image;
18+
int[][] imageArr = convertImageToArray(image);
19+
lock.lock();
20+
try {
21+
for (Filter f : filters.values()) {
22+
imageArr = f.applyFilter(imageArr);
23+
}
24+
if (faceFilter != null) {
25+
imageArr = faceFilter.applyFilter(imageArr);
26+
}
27+
} finally {
28+
lock.unlock();
29+
}
30+
return convertArrayToImage(imageArr);
1831
}
19-
32+
2033
public void addFilter(Filter filter) {
21-
34+
if (filter == null) {
35+
return;
36+
}
37+
lock.lock();
38+
try {
39+
switch (filter.getType()) {
40+
case FACE_DETECTION:
41+
faceFilter = filter;
42+
break;
43+
default:
44+
filters.put(filter.getType(), filter);
45+
}
46+
} finally {
47+
lock.unlock();
48+
}
2249
}
23-
24-
public void removeFilter(Filter filter) {
25-
50+
51+
public void removeFilter(FilterType type) {
52+
if (type == null) {
53+
return;
54+
}
55+
lock.lock();
56+
try {
57+
switch (type) {
58+
case FACE_DETECTION:
59+
faceFilter = null;
60+
break;
61+
default:
62+
filters.remove(type);
63+
}
64+
} finally {
65+
lock.unlock();
66+
}
2667
}
27-
68+
69+
public static int[][] convertImageToArray(BufferedImage image) {
70+
71+
int width = image.getWidth();
72+
int height = image.getHeight();
73+
int[][] result = new int[height][width];
74+
75+
for (int row = 0; row < height; row++) {
76+
for (int col = 0; col < width; col++) {
77+
result[row][col] = image.getRGB(col, row);
78+
}
79+
}
80+
81+
return result;
82+
}
83+
84+
public static BufferedImage convertArrayToImage(int[][] array) {
85+
if (array == null || array.length == 0) {
86+
return null;
87+
}
88+
final int height = array.length;
89+
final int weight = array[0].length;
90+
BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_ARGB);
91+
for (int y = 0; y < height; y++) {
92+
for (int x = 0; x < weight; x++) {
93+
image.setRGB(x, y, array[y][x]);
94+
}
95+
}
96+
return image;
97+
}
98+
2899
}

src/com/siv/filter/FilterType.java

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum FilterType {
88

99
GRAY,
1010
MEDIAN,
11+
CANNY,
1112
FACE_DETECTION
1213

1314
}

src/com/siv/filter/GrayFilter.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.siv.filter;
2+
3+
/**
4+
*
5+
* @author Ilya
6+
*/
7+
public class GrayFilter implements Filter {
8+
9+
@Override
10+
public int[][] applyFilter(final int[][] image) {
11+
final int height = image.length;
12+
final int width = image[0].length;
13+
final int[][] res = new int[height][width];
14+
int value;
15+
for (int y = 0; y < height; y++) {
16+
for (int x = 0; x < width; x++) {
17+
value = image[y][x];
18+
final int rr = (value << 8) >>> 24;
19+
final int gg = (value << 16) >>> 24;
20+
final int bb = (value << 24) >>> 24;
21+
final int gray =(int) ((0.2125 * rr) + (0.7154 * gg) + (0.0721 * bb));
22+
final int color = ((255 & 0xFF) << 24) |
23+
((gray & 0xFF) << 16) |
24+
((gray & 0xFF) << 8) |
25+
((gray & 0xFF));
26+
res[y][x] = color;
27+
}
28+
}
29+
return res;
30+
}
31+
32+
@Override
33+
public FilterType getType() {
34+
return FilterType.GRAY;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)