Hi hello samuel, i am new to java and i try this code to detect face
using haarscade classifier, where is should put the cvSetImageROI to
crop only the face ?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cv;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacpp.Loader;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
/**
*
* @author siubie
*/
public class deteksi {
private static final int SCALE = 2;
// scaling factor to reduce size of input image
// cascade definition for face detection
private static final String CASCADE_FILE =
"haarcascade_frontalface_alt.xml";
public static void detektor(String gambar){
if (gambar.length() < 0) {
System.out.println("No Input File");
return;
}
System.out.println("Starting OpenCV...");
// preload the opencv_objdetect module to work around a known
bug
Loader.load(opencv_objdetect.class);
// load an image
System.out.println("Loading image from " + gambar);
IplImage origImg = cvLoadImage(gambar);
// convert to grayscale
IplImage grayImg = IplImage.create(origImg.width(),
origImg.height(), IPL_DEPTH_8U, 1);
cvCvtColor(origImg, grayImg, CV_BGR2GRAY);
// scale the grayscale (to speed up face detection)
IplImage smallImg = IplImage.create(grayImg.width() / SCALE,
grayImg.height() / SCALE, IPL_DEPTH_8U, 1);
cvResize(grayImg, smallImg, CV_INTER_LINEAR);
// equalize the small grayscale
IplImage equImg = IplImage.create(smallImg.width(),
smallImg.height(), IPL_DEPTH_8U, 1);
cvEqualizeHist(smallImg, equImg);
// create temp storage, used during object detection
CvMemStorage storage = CvMemStorage.create();
// instantiate a classifier cascade for face detection
CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(
cvLoad(CASCADE_FILE));
System.out.println("Detecting faces...");
CvSeq faces = cvHaarDetectObjects(equImg, cascade, storage,
1.1, 3,
CV_HAAR_DO_CANNY_PRUNING);
cvClearMemStorage(storage);
// iterate over the faces and draw yellow rectangles around
them
int total = faces.total();
System.out.println("Found " + total + " face(s)");
for (int i = 0; i < total; i++) {
CvRect r = new CvRect(cvGetSeqElem(faces, i));
cvRectangle(origImg, cvPoint(r.x() * SCALE, r.y() *
SCALE), // undo the scaling
cvPoint((r.x() + r.width()) * SCALE, (r.y() +
r.height()) * SCALE),
CvScalar.BLUE, 6, CV_AA, 0);
}
if (total > 0) {
System.out.println("Saving marked-faces version of " +
gambar + " in " + gambar);
cvSaveImage(gambar, origImg);
}
}
}
On Apr 15, 9:47 am, Samuel Audet <
samuel.au...@gmail.com> wrote:
> Hello,
>
> Simply calling cvSetImageROI() on the input image willcropit...
>
> Samuel
>
> On 2012-04-09 01:43, Issamou wrote:
>
>
>
>
>
>
>
> > Dear all,
>
> > Using a camera to perform the task of Surveillance, I am planning to
> > make my camera save a video frame whenever it detects afaceobject in