@RequestMapping(value = "/uploadfiles", method = RequestMethod.POST)
public @ResponseBody
String getFile(MultipartHttpServletRequest request, HttpServletResponse response) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier faceDetector = new CascadeClassifier("haarcascade_frontalface_alt.xml");
String imageString = null;
Iterator<String> itr = request.getFileNames();
MultipartFile mpf = request.getFile(itr.next());
try {
String fileType = mpf.getContentType(); //image/jpeg
byte[] basArr = mpf.getBytes();
InputStream fileIS = mpf.getInputStream();
Mat basImage = * how convert byte[](basArr) to Mat (basImage)? *;
//face detection
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(basImage, faceDetections);
for (Rect rect : faceDetections.toArray()) {
Imgproc.rectangle(basImage, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
byte[] resultArr = * how back convert Mat(basImage) to byte[](resultArr) ? *;
BASE64Encoder encoder = new BASE64Encoder();
imageString = encoder.encode(resultArr);
} catch (IOException e) {
e.printStackTrace();
}
return imageString;
}