HI all.
I'm a beginner in android so i have a little difficulty to use openCV here.
For my studies i'm doing a face detection for opportunely image processing of that ROI. So i've the code in c++ that work, seeing the official documentation and my c++ code i tried to porting on android, my application work without crash but i can't to draw any rectangle for the faces. I was hoping you could give me any advice for detect and solve my mistake
Here the code that do face detection:
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame)
{
Mat image = new Mat();
Mat tmp = new Mat();
//Convert to RGB
image=inputFrame.rgba();
Imgproc.cvtColor(image, image, Imgproc.COLOR_RGBA2RGB);
tmp = image.clone();
//JUST A TEST
//convert to grayscale (the approach works on grayscale images only)
if (image.channels() == 3)
{
Imgproc.cvtColor(image, tmp, Imgproc.COLOR_RGB2GRAY);
}
CascadeClassifier face_cascade = new CascadeClassifier();
String filename="../../resources/lbpcascade_frontalface.xml";
face_cascade.load(filename);
MatOfRect faces = new MatOfRect();
//if (face_cascade != null)
//{
face_cascade.detectMultiScale(tmp, faces, 1.1, 2, 2, new Size(0,0),new Size());
//}
Rect[] face_cropped = faces.toArray();
Mat faceROI;
//for each face found...
for (int i=0; i< face_cropped.length; i++)
{
Core.rectangle(image, face_cropped[i].tl(),face_cropped[i].br(),new Scalar(0,255,0,255),3);
}
if (CameraMod >= 2) //for detect if devices has 2 cameras
//in the case of 2 cameras it takes the front camera
Core.flip(image, image, 1);
//return image;
return image;
};
↧