-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultipleFaces.java
90 lines (84 loc) · 4.02 KB
/
MultipleFaces.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Created by SAJAL TYAGI
* 31-12-2015
* 12:27 IST
*/
import com.googlecode.javacpp.Loader;
import static com.googlecode.javacv.cpp.opencv_core.CV_AA;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvRect;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_core.cvClearMemStorage;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_core.cvFont;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSeqElem;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_core.cvLoad;
import static com.googlecode.javacv.cpp.opencv_core.cvPoint;
import static com.googlecode.javacv.cpp.opencv_core.cvPutText;
import static com.googlecode.javacv.cpp.opencv_core.cvRectangle;
import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_CAP_ANY;
import com.googlecode.javacv.cpp.opencv_highgui.CvCapture;
import static com.googlecode.javacv.cpp.opencv_highgui.cvCreateCameraCapture;
import static com.googlecode.javacv.cpp.opencv_highgui.cvQueryFrame;
import static com.googlecode.javacv.cpp.opencv_highgui.cvShowImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvWaitKey;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_BGR2GRAY;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_INTER_LINEAR;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvEqualizeHist;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvResize;
import com.googlecode.javacv.cpp.opencv_objdetect;
import static com.googlecode.javacv.cpp.opencv_objdetect.CV_HAAR_DO_CANNY_PRUNING;
import com.googlecode.javacv.cpp.opencv_objdetect.CvHaarClassifierCascade;
import static com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects;
public class MultipleFaces {
public static void main(String[] args) {
Loader.load(opencv_objdetect.class);
// String name = "E:\\movie\\video songs\\Sajal.wmv";
CvCapture capture = cvCreateCameraCapture(CV_CAP_ANY);
IplImage org = null, gray = null, small = null;
int scale = 2;
CvMemStorage cms = null;
CvSeq cs;
int total = 0;
int bal = 1;
while (bal == 1) {
org = cvQueryFrame(capture);
if (org == null) {
break;
}
gray = cvCreateImage(cvGetSize(org), 8, 1);
cvCvtColor(org, gray, CV_BGR2GRAY);
small = IplImage.create(gray.width() / scale, gray.height() / scale, 8, 1);
cvResize(gray, small, CV_INTER_LINEAR);
cvEqualizeHist(small, small);
cms = CvMemStorage.create();
CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(
cvLoad("E:\\Downloads\\Java projects\\JavaCV\\src\\com\\facedetect\\haarcascade_frontalface_alt.xml"));
cs = cvHaarDetectObjects(small, cascade, cms, 1.1, 3,
CV_HAAR_DO_CANNY_PRUNING);
total = cs.total();
if (total > 0) {
for (int i = 0; i < total; i++) {
CvRect r = new CvRect(cvGetSeqElem(cs, i));
cvRectangle(org, cvPoint(r.x() * scale, r.y() * scale),
cvPoint((r.x() + r.width()) * scale, (r.y() + r.height()) * scale),
CvScalar.YELLOW, 6, CV_AA, 0);
}
}
if ((char) cvWaitKey(1) == 'q') {
break;
}
cvPutText(org, "#SAJAL", cvPoint(40, 40), cvFont(scale, 5), new CvScalar(0, 0, 255, 1));
cvShowImage("Video", org);
}
cvReleaseImage(org);
cvReleaseImage(gray);
cvReleaseImage(small);
cvClearMemStorage(cms);
}
}