chooseXmlDetectionFile();
}
int detectionCount = 0;
CvSeq faces = null;
while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) {
cvSmooth(frame, frame, CV_GAUSSIAN, 9, 9, 2, 2);
detectionCount++;
if (detectionCount > 5) {
detectionCount=0;
IplImage grayImage = null;
try {
grayImage = IplImage.create(frame.width(),
frame.height(), IPL_DEPTH_8U, 1);
} catch (NullPointerException e) {
System.out.println("Error: " + e);
System.out.println("Check image file!");
System.exit(1);
}
// We convert the original image to grayscale.
cvCvtColor(frame, grayImage, CV_BGR2GRAY);
// We instantiate a classifier cascade to be used for detection, using
// the cascade definition.
CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(
cvLoad(detectionXmlFile));
// We detectionExecute the faces.
faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1,
0);
}
if (faces!=null) {
// We iterate over the discovered faces and draw yellow rectangles
// around them.
for (int i = 0; i < faces.total(); i++) {
CvRect r = new CvRect(cvGetSeqElem(faces, i));
cvRectangle(frame, cvPoint(r.x(), r.y()),
cvPoint(r.x() + r.width(), r.y() + r.height()),
CvScalar.YELLOW, 1, CV_AA, 0);