Example usage for org.opencv.objdetect CascadeClassifier CascadeClassifier

List of usage examples for org.opencv.objdetect CascadeClassifier CascadeClassifier

Introduction

In this page you can find the example usage for org.opencv.objdetect CascadeClassifier CascadeClassifier.

Prototype

public CascadeClassifier() 

Source Link

Usage

From source file:com.ibm.streamsx.edgevideo.device.FaceDetector.java

License:Open Source License

/**
 * Create a new instance using the specified {@link CascadeClassifier}.
 * @param faceClassifierPath path to the classifier - e.g. haarcascade_frontalface_alt.xml
 * @throws IOException /*from   ww w. j  a v a  2 s . c o m*/
 */
public FaceDetector(File faceClassifierPath) throws IOException {
    CascadeClassifier faceClassifier = new CascadeClassifier();
    boolean loaded = faceClassifier.load(faceClassifierPath.toString());
    if (!loaded) {
        throw new IOException("Error loading face classifier path: " + faceClassifierPath);
    }
    this.faceClassifier = faceClassifier;
}

From source file:detectors.CCdetection.java

/**
 * Method to scan image with x classifier
 *//*from   ww  w .  j  a v a2 s . c om*/
public void scanImage(String path) {
    CascadeClassifier faceCC = new CascadeClassifier();
    faceCC.load("res/haarcascade_frontalface_alt.xml");

    //Matrix to hold image to be scanned
    Mat image = new Mat();
    image = Highgui.imread(path, IMREAD_COLOR);

    Mat rgb = new Mat();
    Mat gray = new Mat();
    image.copyTo(rgb);
    image.copyTo(gray);

    //Create integral image from the grayscale version of frame 
    Imgproc.cvtColor(rgb, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.equalizeHist(gray, gray);

    //MatOfRect detection window initialized
    MatOfRect detects = new MatOfRect();
    faceCC.detectMultiScale(gray, detects);

    //Print out number of detected rect objects detected
    if (detects.toArray().length != 0) {
        System.out.printf("Detected %s\n", detects.toArray().length);
    }
}

From source file:detectors.CCdetection.java

/**
 * Method to scan video with x classifier
 * NOT COMPLETE//from  ww  w .  j  ava  2 s. c  o  m
 */
public void scanVideo() {
    //Initialize video capture object to 0(default camera device)
    VideoCapture vc = new VideoCapture(0);

    //String path = "";

    //Initialize and load in classifier
    CascadeClassifier faceCC = new CascadeClassifier();
    faceCC.load("res/haarcascade_frontalface_default.xml");

    //Matrix(opencv core image object) to hold the image frame coming from the capture stream
    Mat image = new Mat();

    boolean isFound = false;
    while (!isFound) {
        //VideoCapture read combines grab and retrieve methods to decode and return the frame
        vc.read(image);
        if (image != null) {

            //Initialize new Mats to hold the original colored frame and the grayscaled frame
            Mat rgb = new Mat();
            Mat gray = new Mat();
            image.copyTo(rgb);
            image.copyTo(gray);

            //Create integral image from the grayscale version of frame 
            Imgproc.cvtColor(rgb, gray, Imgproc.COLOR_BGR2GRAY);
            Imgproc.equalizeHist(gray, gray);

            //MatOfRect detection window initialized
            MatOfRect detects = new MatOfRect();
            faceCC.detectMultiScale(gray, detects);

            //Print out number of detected rect objects detected
            if (detects.toArray().length != 0) {
                System.out.printf("Detected %s\n", detects.toArray().length);
                //prodFound(UPC,"T");
                isFound = true;
            }

        } else {
            break;
        }
    }
}

From source file:org.pidome.client.userdetection.faces.FD_Controller.java

/**
 * Init the controller variables// w ww .j  a  v a 2 s.c  o  m
 */
public final void init() {
    this.capture = new VideoCapture();
    this.faceCascade = new CascadeClassifier();
    this.absoluteFaceSize = 0;
}

From source file:org.pidome.client.userdetection.faces.FD_Controller.java

/**
 * When the Haar checkbox is selected, deselect the other one and load the
 * proper XML classifier//from w ww  .j av a  2 s .  c  o m
 *
 */
@FXML
protected void haarSelected() {
    // check whether the lpb checkbox is selected and deselect it
    if (this.lbpClassifier.isSelected()) {
        this.lbpClassifier.setSelected(false);
    }
    this.faceCascade = new CascadeClassifier();
    this.checkboxSelection("lib/opencv/haarcascade_frontalface_alt.xml");
}

From source file:org.pidome.client.video.capture.faces.recognition.FaceDetection.java

public FaceDetection() {
    this.faceCascade = new CascadeClassifier();
    this.faceCascade.load("lib/opencv/haarcascade_frontalface_alt.xml");
}

From source file:org.wso2.carbon.cep.objectdetection.siddhiextension.ObjectDetectionExtension.java

License:Open Source License

/**
 * Detect objects using OpenCV.//from  w  w  w .j a  v a  2 s  . c o  m
 *
 * @param imageHex
 *            the image hex string
 * @param cascadePath
 *            the cascade path
 * @return the detected object count
 */
private long detectObjects(String imageHex, String cascadePath) {
    long objectCount = 0;
    try {
        // conversion to Mat
        byte[] imageByteArr = (byte[]) new Hex().decode(imageHex);
        Mat image = Highgui.imdecode(new MatOfByte(imageByteArr), Highgui.IMREAD_UNCHANGED);

        // initializing classifier
        CascadeClassifier cClassifier = new CascadeClassifier();
        cClassifier.load(cascadePath);

        // pre-processing
        Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2GRAY);
        Imgproc.equalizeHist(image, image);

        // detecting objects
        MatOfRect imageRect = new MatOfRect();
        cClassifier.detectMultiScale(image, imageRect);

        // image count
        objectCount = ((Integer) imageRect.toList().size()).longValue();
    } catch (DecoderException e) {
        e.printStackTrace();
    }

    return objectCount;
}