0

I'm trying to blur the faces of all people detected by the webcam. The problem is that when the webcam detect a face the program shows the crop mat with the blur face.

I tried to put the blur face into the original mat but it doesn't work.

for(Rect rect : faces.toArray()){
    Imgproc.rectangle(frame, rect.tl(), rect.br(), new Scalar(0,0,255),3);
    Rect rectCrop = new Rect(rect.x, rect.y , rect.width, rect.height);
    Mat imageROI = grayFrame.submat(rectCrop);

    //frame is the original mat with the correct size
    Imgproc.GaussianBlur(imageROI, frame, new Size(55, 55), 55);
}

No face detection:

No face detection

With face detection:

With face detection

CinCout
  • 9,486
  • 12
  • 49
  • 67

1 Answers1

2

use this constructor of Mat

Mat imageROI = new Mat(grayFrame,rectCrop);

instead of

 Mat imageROI = grayFrame.submat(rectCrop);

The constructor gives you reference to the data matrix that is owned by grayFrame. so any modifications to submat will effect the bigmat.The submat gives copy of the grayFrame data matrix for the crop rectangle. So the modifications on the submat will not effect the bigmat.

hariprasad
  • 838
  • 1
  • 8
  • 16