Java OpenCV - detecting ROI, creating submat and copy to original mat

[亡魂溺海] 提交于 2019-12-12 03:13:32

问题


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:

With face detection:


回答1:


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.



来源:https://stackoverflow.com/questions/37849313/java-opencv-detecting-roi-creating-submat-and-copy-to-original-mat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!