I am having OpenCV Error:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\array.cpp, line 2494
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\array.cpp:2494: error: (-206) Unrecognized or unsupported array type in function cvGetMat]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_0(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:94)
at main.com.wyun.facedetection.FaceDetector.main(FaceDetector.java:51) Java Result: 1
when I have used
faceDetector.detectMultiScale(image, faceDetections, 1.1, 3, Objdetect.CASCADE_FIND_BIGGEST_OBJECT | Objdetect.CASCADE_SCALE_IMAGE, minSize, maxSize);
This is my code:
public class DetectFace {
public static void main(String[] args) {
System.load(System.getProperty("user.dir") + "\\resources\\opencv_java300.dll");
CascadeClassifier faceDetector = new CascadeClassifier(System.getProperty("user.dir") + "\\resources\\haarcascade_frontalface_alt.xml");
Mat image = Imgcodecs.imread(System.getProperty("user.dir") + "\\resources\\upload.png");
MatOfRect faceDetections = new MatOfRect();
MatOfInt rejectLevels = new MatOfInt();
MatOfDouble levelWeights = new MatOfDouble();
Size minSize = new Size(45, 45);
Size maxSize = new Size(300, 300);
faceDetector.detectMultiScale(image, faceDetections, 1.1, 3, Objdetect.CASCADE_FIND_BIGGEST_OBJECT | Objdetect.CASCADE_SCALE_IMAGE, minSize, maxSize);
System.out.println(String.format("Detected %s faces",
faceDetections.toArray().length));
for (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));
}
String filename = "ouput.png";
System.out.println(String.format("Writing %s", filename));
Imgcodecs.imwrite(filename, image);
}
}
↧