Can't find any faces on pictures
I'm java programmer and I'm using opencv-2413.jar
library.
ByteArrayOutputStream streamBA = new ByteArrayOutputStream();
//wi - is instance of WritableImage (images with faces are big: 720p and 1080p, and correct. I save it to disk and they opens well)
RenderedImage ri = SwingFXUtils.fromFXImage(wi, null);
ImageIO.write(ri, "jpg", streamBA);
byte[] img = streamBA.toByteArray();
MatOfByte rawImage = new MatOfByte(img);
Mat image = Highgui.imdecode(rawImage, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
System.out.println(image.toString());
MatOfRect faces = new MatOfRect();
// I'm trying different cascades, the result is the same
CascadeClassifier faceDetector = new CascadeClassifier(<path/to/cascade>);
faceDetector.detectMultiScale(image, faces);
System.out.println(faces.elemSize() + "\n");
for (Rect r : faces.toList()) {
System.out.println(r.x + " " + r.y);
}
Everything is going ok, but faces.elemSize()
is always 0
. What I'm doing wrong?
it's most likely the Cascade. please check if it was loaded correctly
can you tell us the path you're using ?
String pathToCascade = getClass().getResource("/haarcascades/haarcascade_frontalface_alt2.xml").getPath();
. And I tried simpleC:\haarcascade_frontalface_alt2.xml
, the result is the same.try
C:/haarcascade_frontalface_alt2.xml
or any absolute path with forward slashes. thegetResource()
thing is a broken idea on win.