I want to make app which swap faces in picture. The mat of the picture is picMat, and I want to copy a mat of detected face on picmat, but the function copyTo don't work. here is the code:
Bitmap faceBitmap;
SparseArray<Face> faces = faceDetector.detect(frame);
for(int i=0; i<faces.size(); i++) {
Face thisFace = faces.valueAt(i);
faceBitmap = Bitmap.createBitmap(frame.getBitmap(), (int) thisFace.getPosition().x,
(int) thisFace.getPosition().y, (int) thisFace.getWidth(), (int) thisFace.getHeight());
Mat temp = new Mat();
faceBitmap = faceBitmap.copy(Bitmap.Config.ARGB_8888, true);
bitmapToMat(faceBitmap, temp);
float x1 = thisFace.getPosition().x;
float y1 = thisFace.getPosition().y;
float x2 = x1 + thisFace.getWidth();
float y2 = y1 + thisFace.getHeight();
Rect temp_rect = new Rect((int)x1,(int)y1,temp.cols(),temp.rows());
rects.add(temp_rect);
if(i==3){
temp.copyTo( picMat.submat( rects.get(0)) );
}
}
Bitmap img = Bitmap.createBitmap(picMat.cols(), picMat.rows(),Bitmap.Config.ARGB_8888);
matToBitmap(picMat, img);
imageView.setImageBitmap(img);