Ask Your Question
0

Can't find any faces on pictures

asked 2016-07-28 02:40:54 -0600

KorobOK gravatar image

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?

edit retag flag offensive close merge delete

Comments

1

it's most likely the Cascade. please check if it was loaded correctly

can you tell us the path you're using ?

berak gravatar imageberak ( 2016-07-28 04:35:10 -0600 )edit

String pathToCascade = getClass().getResource("/haarcascades/haarcascade_frontalface_alt2.xml").getPath();. And I tried simple C:\haarcascade_frontalface_alt2.xml, the result is the same.

KorobOK gravatar imageKorobOK ( 2016-07-28 18:14:06 -0600 )edit
2

try C:/haarcascade_frontalface_alt2.xml or any absolute path with forward slashes. the getResource() thing is a broken idea on win.

berak gravatar imageberak ( 2016-07-28 20:29:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-07-31 23:24:11 -0600

KorobOK gravatar image

updated 2016-07-31 23:24:32 -0600

The problem was in Cyrillic symbols in path. I remove these and replace my code by following:

String pathToCascade = Paths.get(
                    getClass().getResource("/haarcascades/haarcascade_frontalface_alt.xml")
.toURI().normalize()).toString();
faceDetector = new CascadeClassifier(pathToCascade);


Thanks to @Barek

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-28 02:40:29 -0600

Seen: 278 times

Last updated: Jul 31 '16