Java Code Examples for org.opencv.objdetect.CascadeClassifier#load()
The following examples show how to use
org.opencv.objdetect.CascadeClassifier#load() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetectEyes.java From classchecks with Apache License 2.0 | 6 votes |
/** * 检测左眼 * @param faceImg * @param leftEyePoint * @param searchedLeftEye * @param scaledWidth */ protected static void detectLeftEye(Mat faceImg, Rect leftEyeRect, int scaledWidth) { CascadeClassifier cascade = new CascadeClassifier(); cascade.load(DetectorXMLPath + HAARCASCADE_MCS_LEFTEYE); // 第一次检测左眼 if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth); } // 如果没有检测到眼睛,使用不同的级联加载器继续尝试 if(leftEyeRect.width <= 0) { cascade.load(DetectorXMLPath+HAARCASCADE_EYE_TREE_EYEGLASSES); if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth); } } if(leftEyeRect.width <= 0) { cascade.load(DetectorXMLPath+HAARCASCADE_EYE); if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth); } } }
Example 2
Source File: DetectEyes.java From classchecks with Apache License 2.0 | 6 votes |
protected static void detectRightEye(Mat faceImg, Rect rightEyeRect, int scaledWidth) { CascadeClassifier cascade = new CascadeClassifier(); cascade.load(DetectorXMLPath+HAARCASCADE_MCS_RIGHTEYE); // 第一次检测右眼 if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth); } if(rightEyeRect.width <= 0) { cascade.load(DetectorXMLPath+HAARCASCADE_EYE_TREE_EYEGLASSES); if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth); } } if(rightEyeRect.width <= 0) { cascade.load(DetectorXMLPath+HAARCASCADE_EYE); if(!cascade.empty()) { DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth); } } }
Example 3
Source File: CameraStream.java From tutorials with MIT License | 6 votes |
public static Mat detectFace(Mat inputImage) { MatOfRect facesDetected = new MatOfRect(); CascadeClassifier cascadeClassifier = new CascadeClassifier(); int minFaceSize = Math.round(inputImage.rows() * 0.1f); cascadeClassifier.load("./src/main/resources/haarcascades/haarcascade_frontalface_alt.xml"); cascadeClassifier.detectMultiScale(inputImage, facesDetected, 1.1, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(minFaceSize, minFaceSize), new Size() ); Rect[] facesArray = facesDetected.toArray(); for(Rect face : facesArray) { Imgproc.rectangle(inputImage, face.tl(), face.br(), new Scalar(0, 0, 255), 3 ); } return inputImage; }
Example 4
Source File: FaceDetection.java From tutorials with MIT License | 6 votes |
public static void detectFace(String sourceImagePath, String targetImagePath) { Mat loadedImage = loadImage(sourceImagePath); MatOfRect facesDetected = new MatOfRect(); CascadeClassifier cascadeClassifier = new CascadeClassifier(); int minFaceSize = Math.round(loadedImage.rows() * 0.1f); cascadeClassifier.load("./src/main/resources/haarcascades/haarcascade_frontalface_alt.xml"); cascadeClassifier.detectMultiScale(loadedImage, facesDetected, 1.1, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(minFaceSize, minFaceSize), new Size() ); Rect[] facesArray = facesDetected.toArray(); for(Rect face : facesArray) { Imgproc.rectangle(loadedImage, face.tl(), face.br(), new Scalar(0, 0, 255), 3 ); } saveImage(loadedImage, targetImagePath); }
Example 5
Source File: FDOpenCVPresenter.java From Image-Detection-Samples with Apache License 2.0 | 5 votes |
private synchronized CascadeClassifier initializeJavaDetector(File cascadeFile) { CascadeClassifier detector = new CascadeClassifier(cascadeFile.getAbsolutePath()); detector.load(cascadeFile.getAbsolutePath()); if (detector.empty()) { Log.e(TAG, "Failed to load cascade classifier"); detector = null; } else { Log.i(TAG, "Loaded cascade classifier from " + cascadeFile.getAbsolutePath()); } return detector; }