當前位置: 首頁>>代碼示例>>Java>>正文


Java CascadeClassifier.detectMultiScale方法代碼示例

本文整理匯總了Java中org.opencv.objdetect.CascadeClassifier.detectMultiScale方法的典型用法代碼示例。如果您正苦於以下問題:Java CascadeClassifier.detectMultiScale方法的具體用法?Java CascadeClassifier.detectMultiScale怎麽用?Java CascadeClassifier.detectMultiScale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.objdetect.CascadeClassifier的用法示例。


在下文中一共展示了CascadeClassifier.detectMultiScale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loop

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public static void loop (CascadeClassifier classifier, Mat mat, ImgWindow window, VideoCapture video) {
	video.read(mat);
	System.out.println(mat);
	if (!mat.empty()) {
		MatOfRect rects = new MatOfRect();
		long start = System.nanoTime();
		classifier.detectMultiScale(mat, rects);
		System.out.println((System.nanoTime()-start)/1000000000.0);
		window.setImage(mat);
		Graphics2D g = window.begin();
		g.setColor(Color.RED);
		for(Rect r: rects.toArray()) {
			g.drawRect(r.x, r.y, r.width, r.height);
		}
		window.end();
	}
}
 
開發者ID:badlogic,項目名稱:opencv-fun,代碼行數:18,代碼來源:FaceDetectionTest.java

示例2: run

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public void run() {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  String base = "C:/Books in Progress/Java for Data Science/Chapter 10/OpenCVExamples/src/resources";
  CascadeClassifier faceDetector = 
          new CascadeClassifier(base + "/lbpcascade_frontalface.xml");
  
  Mat image = Imgcodecs.imread(base + "/images.jpg");

  MatOfRect faceVectors = new MatOfRect();
  faceDetector.detectMultiScale(image, faceVectors);

  out.println(faceVectors.toArray().length + " faces found");

  for (Rect rect : faceVectors.toArray()) {
      Imgproc.rectangle(image, new Point(rect.x, rect.y), 
              new Point(rect.x + rect.width, rect.y + rect.height), 
              new Scalar(0, 255, 0));
  }
  Imgcodecs.imwrite("faceDetection.png", image);
}
 
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:21,代碼來源:DetectFaceDemo.java

示例3: dobj

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
private static Mat dobj(CascadeClassifier objDetector, Mat src) {
	final Mat dst = src.clone();

	final MatOfRect objDetections = new MatOfRect();

	objDetector.detectMultiScale(dst, objDetections);

	if (objDetections.toArray().length <= 0) {
		return src;
	}
	for (final Rect rect : objDetections.toArray()) {
		Imgproc.rectangle(dst, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
				new Scalar(0, 0, 255), 2);
	}
	return dst;
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:17,代碼來源:CameraFacialRecognition.java

示例4: staticFace

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public static void staticFace(String input, String output) {

		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		System.out.println("\nRunning FaceDetector");

		final CascadeClassifier faceDetector = new CascadeClassifier(StaticFacialRecognition.class
				.getResource("../../../../../opencv/sources/data/haarcascades_cuda/haarcascade_frontalface_alt.xml")
				.getPath().substring(1));
		final Mat image = Imgcodecs.imread(input);
		// �������� StaticFacialRecognition.class.getResource(input).getPath().substring(1)

		final MatOfRect faceDetections = new MatOfRect();
		faceDetector.detectMultiScale(image, faceDetections);

		System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

		for (final Rect rect : faceDetections.toArray()) {
			Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
					new Scalar(0, 255, 0));
		}

		System.out.println(String.format("Writing %s", output));
		Imgcodecs.imwrite(output, image);
		// �������� StaticFacialRecognition.class.getResource("").getPath().substring(1) +
		// output
	}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:27,代碼來源:StaticFacialRecognition.java

示例5: main

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public static void main(String[] args) {
	
	// ָ��������ͼƬ·����������ļ�
    String inputImagePath = identificate.class.getClassLoader().getResource("hf.jpg").getPath().substring(1);
    String outputImageFile = "identificate.png";
    
    String xmlPath = identificate.class.getClassLoader().getResource("cascade_storage.xml").getPath().substring(1);
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    CascadeClassifier faceDetector = new CascadeClassifier(xmlPath);
    Mat image = Highgui.imread(inputImagePath);
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);
    
    // ���������
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255));
    }

    // д�뵽�ļ�
    Highgui.imwrite(outputImageFile, image);
    
    System.out.print("\nOK!");
}
 
開發者ID:nthf,項目名稱:yourface,代碼行數:24,代碼來源:identificate.java

示例6: faceDetect

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public static Rect[] faceDetect(Mat image) {

		// Create a face detector from the cascade file in the resources
        // directory.
        CascadeClassifier faceDetector = new CascadeClassifier(OPENCV_HAARCASCADES_HOME
                + "haarcascade_frontalface_default.xml");

		// Detect faces in the image.
        // MatOfRect is a special container class for Rect.
        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections, 1.2, 4, 0,
                new org.opencv.core.Size(10, 10), new org.opencv.core.Size(
                        1000, 1000));

        System.out.println(String.format("Detected %s faces",
                faceDetections.toArray().length));

        return faceDetections.toArray();

    }
 
開發者ID:samie,項目名稱:trollator,代碼行數:21,代碼來源:TrollatorUI.java

示例7: traitDetection

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
 * Detects the traits and returns the number of detections
 * @param cascade Classifier for the Detection
 * @param trait Name of the trait to be detected
 **/
public int traitDetection(CascadeClassifier cascade, String trait) {
	MatOfRect traits = new MatOfRect();
	// Classifier used for Trait Detection
	if (cascade != null) {
		//	if(cascade == cascadeClassifier2) cascade.detectMultiScale(image, traits, 1.05, 20, 0, new Size(0, 0), new Size(200, 200)); //if eyes
		if(trait.equals("eyes"))  cascade.detectMultiScale(image, traits, 1.05, 10, 0, new Size(0, 0), new Size(300, 300));//	else if(cascade == cascadeClassifier3) cascade.detectMultiScale(image, traits, 1.04, 80, 0, new Size(0, 0), new Size(300, 300)); //if mouth
		else if(trait.equals("mouths")) cascade.detectMultiScale(image, traits, 1.45, 10, 0, new Size(0, 0), new Size(200, 200)); 
		else cascade.detectMultiScale(image, traits, 1.05, 6, 0, new Size(lowerLimit1, lowerLimit2), new Size(upperLimit1, upperLimit2)); //faces
	}

	Rect[] facesArray =traits.toArray();
	for (int i = 0; i <facesArray.length; i++) {
		Core.rectangle(origIm, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0, 255), 2);
	}
	return facesArray.length;
}
 
開發者ID:F4b1-,項目名稱:Pixtern-Library,代碼行數:22,代碼來源:ValidateUploadActivity.java

示例8: detectFaces

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public static Rect[] detectFaces(BufferedImage image)
{
    CascadeClassifier detector = new CascadeClassifier(Thread.currentThread().getContextClassLoader().getResource("haarcascade_frontalface_alt.xml").getFile());
    Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
    byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    mat.put(0, 0, data);
    MatOfRect detections = new MatOfRect();
    detector.detectMultiScale(mat, detections);

    return detections.toArray();
}
 
開發者ID:maksgraczyk,項目名稱:DeepID,代碼行數:12,代碼來源:MainGUI.java

示例9: run

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
@Override
public void run() {
    BufferedImage bi = webcam.getImage();

    //Detect all face samples in the preview
        CascadeClassifier detector = new CascadeClassifier(Thread.currentThread().getContextClassLoader().getResource("haarcascade_frontalface_alt.xml").getFile());
        Mat mat = new Mat(bi.getHeight(), bi.getWidth(), CvType.CV_8UC3);
        byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
        mat.put(0, 0, data);
        MatOfRect detections = new MatOfRect();
        detector.detectMultiScale(mat, detections);

        Rect[] array = detections.toArray();

        if (array.length == 1) { //If there's only one face detected, resize the sample to 150x150 pixels and send it to the model
            BufferedImage bi2 = new BufferedImage(150, 150, BufferedImage.TYPE_INT_RGB);
            Graphics gr = bi2.createGraphics();
            gr.drawImage(bi.getSubimage(array[0].x, array[0].y, array[0].width, array[0].height), 0, 0, 150, 150, null);
            gr.dispose();

            try {
                check(bi2); //sends the image to the model
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
}
 
開發者ID:maksgraczyk,項目名稱:DeepID,代碼行數:28,代碼來源:Identification.java

示例10: buildTemplate

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
 * <p>Build a template from a specific eye area previously substracted
 * uses detectMultiScale for this area, then uses minMaxLoc method to
 * detect iris from the detected eye</p>
 *
 * @param area Preformatted Area
 * @param size minimum iris size
 * @param grayMat image in gray
 * @param rgbaMat image in color
 * @param detectorEye Haar Cascade classifier
 * @return built template
 */
@NonNull
private static Mat buildTemplate(Rect area, final int size,
                                 @NonNull Mat grayMat,
                                 @NonNull Mat rgbaMat,
                                 CascadeClassifier detectorEye) {
    Mat template = new Mat();
    Mat graySubMatEye = grayMat.submat(area);
    MatOfRect eyes = new MatOfRect();
    Rect eyeTemplate;
    detectorEye.detectMultiScale(graySubMatEye, eyes, 1.15, 2,
            Objdetect.CASCADE_FIND_BIGGEST_OBJECT
                    | Objdetect.CASCADE_SCALE_IMAGE, new Size(EYE_MIN_SIZE, EYE_MIN_SIZE),
            new Size());

    Rect[] eyesArray = eyes.toArray();
    if (eyesArray.length > 0) {
        Rect e = eyesArray[0];
        e.x = area.x + e.x;
        e.y = area.y + e.y;
        Rect eyeRectangle = getEyeArea((int) e.tl().x,
                (int) (e.tl().y + e.height * 0.4),
                e.width,
                (int) (e.height * 0.6));
        graySubMatEye = grayMat.submat(eyeRectangle);
        Mat rgbaMatEye = rgbaMat.submat(eyeRectangle);


        Core.MinMaxLocResult minMaxLoc = Core.minMaxLoc(graySubMatEye);

        FaceDrawerOpenCV.drawIrisCircle(rgbaMatEye, minMaxLoc);
        Point iris = new Point();
        iris.x = minMaxLoc.minLoc.x + eyeRectangle.x;
        iris.y = minMaxLoc.minLoc.y + eyeRectangle.y;
        eyeTemplate = getEyeArea((int) iris.x - size / 2,
                (int) iris.y
                        - size / 2, size, size);
        FaceDrawerOpenCV.drawEyeRectangle(eyeTemplate, rgbaMat);
        template = (grayMat.submat(eyeTemplate)).clone();
    }
    return template;
}
 
開發者ID:raulh82vlc,項目名稱:Image-Detection-Samples,代碼行數:54,代碼來源:EyesDetectionInteractorImpl.java

示例11: detectFaces

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
 * Executes the OpenCV "haarcascade_frontalface_alt" cascade classifier on a specific image
 * and returns an array of org.opencv.core.Rect. Each Rect corresponds to a face detected on the image.
 * 
 * <p><b>! Attention !</b> Up to 68 seconds on a Raspberry Pi 2 for a picture of 2592x1944.<br>
 * 4 seconds for a picture of 640x480.</p>
 * 
 * @param image the org.opencv.core.Mat object corresponding to the image to analyze.
 * @return an array of org.opencv.core.Rect. Each Rect corresponds to a face on the image.
 */
public static Rect[] detectFaces(Mat image) {
    CascadeClassifier faceDetector = new CascadeClassifier(haarcascadeFrontalfaceAltXmlFilePath);
    
    MatOfRect faceDetections = new MatOfRect();
    Tools.debug("Detect multiscale: START (timestamp " + new Date() + ")", Tools.Color.ANSI_YELLOW);
    faceDetector.detectMultiScale(image, faceDetections);
    Tools.debug("Detect multiscale: STOP  (timestamp " + new Date() + ")", Tools.Color.ANSI_YELLOW);
    
    return faceDetections.toArray();
}
 
開發者ID:Raspoid,項目名稱:raspoid,代碼行數:21,代碼來源:FaceDetector.java

示例12: compareToCascade

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
public Mat compareToCascade(String cascade, Mat image) {

        CascadeClassifier cascadeDetector = new CascadeClassifier(cascade);
        MatOfRect cascadeDetections = new MatOfRect();
        cascadeDetector.detectMultiScale(image, cascadeDetections);

        System.out.println("Detected cascades: " + cascadeDetections.toArray().length);

        for (Rect rect : cascadeDetections.toArray()) {
            Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                    new Scalar(0, 255, 0));
        }

        return image;
    }
 
開發者ID:andreaslorentzen,項目名稱:dronemis,代碼行數:16,代碼來源:OpenCVHelper.java

示例13: detectFaces

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
private Rect[] detectFaces(Mat image, CascadeClassifier cascadeClassifier, DetectionBasedTracker detectionBasedTracker) {
	MatOfRect faces = new MatOfRect();
	if (mDetectorType == JAVA_DETECTOR) {
		if (cascadeClassifier != null)
			cascadeClassifier.detectMultiScale(image, faces, 1.1, 2, 2, // opencvtodo:
																		// objdetect.CV_HAAR_SCALE_IMAGE
					new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
	} else if (mDetectorType == NATIVE_DETECTOR) {
		if (detectionBasedTracker != null)
			detectionBasedTracker.detect(image, faces);
	} else {
		Log.e(TAG, "Detection method is not selected!");
	}
	return faces.toArray();
}
 
開發者ID:mobilesec,項目名稱:authentication-framework-module-face,代碼行數:16,代碼來源:FaceDetectionActivity.java

示例14: detectarFaces

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/***
 * 
 * @param cascadeClassifier
 * @param mat
 * @return
 */
public MatOfRect detectarFaces(CascadeClassifier cascadeClassifier, Mat mat){
	
	MatOfRect matOfRect = new MatOfRect();
	cascadeClassifier.detectMultiScale(mat, matOfRect);
	
	return matOfRect;
}
 
開發者ID:rafaelguinho,項目名稱:HidingHerFace,代碼行數:14,代碼來源:ServiceExtracaoFacesImagem.java

示例15: processVideo

import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
@Override
public Collection<DetectedVehicle> processVideo(Path video, DateTime startDateTime)
{
    CascadeClassifier carDetector = new CascadeClassifier("/Users/luke/working/car-counter/data/cars3.xml");


    VideoCapture videoCapture = new VideoCapture();
    videoCapture.open("/Users/luke/working/car-counter/data/video1.m4v");

    int index = 0;

    while (true)
    {
        if (!videoCapture.read(image))
        {
            break;
        }

        System.out.print(".");

        //processFrame();

        MatOfRect carDetections = new MatOfRect();
        carDetector.detectMultiScale(image, carDetections);

        System.out.println(String.format("Detected %s cars", carDetections.toArray().length));

        // Draw a bounding box around each hit
        for (Rect rect : carDetections.toArray())
        {
            Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(0, 255, 0));
        }

        String file = String.format("/Users/luke/working/car-counter/data/out/out-%03d.jpg", index++);
        org.opencv.highgui.Highgui.imwrite(file, image);
    }

    return null;
}
 
開發者ID:tmyroadctfig,項目名稱:car-counter,代碼行數:41,代碼來源:OpencvCarCounter.java


注:本文中的org.opencv.objdetect.CascadeClassifier.detectMultiScale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。