Ask Your Question

mushroom's profile - activity

2020-09-28 13:34:31 -0600 received badge  Notable Question (source)
2018-05-17 12:14:08 -0600 received badge  Popular Question (source)
2016-04-08 11:49:35 -0600 received badge  Student (source)
2014-04-13 14:35:28 -0600 commented question Get jpeg encoded in base64 string into Mat in Java.

@berak The results didn't change. However, I noticed that when I tried writing out the image using Highgui.imwrite, the image is empty. This might explain why no faces are detected. Any thoughts on why the image turns up empty? The byte array that I am using to create the Mat is not empty.

2014-04-13 14:06:27 -0600 commented question Get jpeg encoded in base64 string into Mat in Java.

@berak Can you elaborate? I had seen that function before, but it takes a Mat as input.

2014-04-13 13:27:26 -0600 asked a question Get jpeg encoded in base64 string into Mat in Java.

I am trying to do a simple face detection example in Java, similar to what was done in the Introduction to Java Development article. When I load a jpeg image using Highgui.imread(path), everything works fine. But the images I am using come from an API that returns base64 encoded jpegs. My code for handling the base64 strings looks like this:

CascadeClassifier classifier = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());

// img is a String
byte[] bytes = parseBase64Binary(img); // This function is found in javax.xml.bind.DatatypeConverter
Mat image = new Mat;
image.put(0, 0, bytes);
MatOfRect faceDetections = new MatOfRect();
classifier.detectMultiScale(image, faceDetections);

This does not work. I tested it by encoding an image in which a face was successfully detected when loaded directly:

DataBufferByte byteBuffer = (DataBufferByte) ImageIO.read(new File(path_to_file_that_worked_before)).getRaster.getDataBuffer();
String img = printBase64Binary(byteBuffer.getData);

No faces are detected. Any idea what I am doing wrong?