Java OpenCV - 检测 ROI,创建子垫并复​​制到原始垫

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

我正在尝试模糊网络摄像头检测到的所有人的面孔。 问题是,当网络摄像头检测到人脸时,程序会显示带有模糊人脸的裁剪垫。

我试着把模糊的脸放到原来的垫子里,但没用。

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);
}

没有人脸检测:

使用人脸检测:

使用 Mat 的这个构造函数

Mat imageROI = new Mat(grayFrame,rectCrop);

而不是

 Mat imageROI = grayFrame.submat(rectCrop);

构造函数为您提供对 grayFrame 拥有的数据矩阵的引用。因此对 submat 的任何修改都会影响 bigmat.The submat 为裁剪矩形提供 grayFrame 数据矩阵的副本。所以对 submat 的修改不会影响 bigmat。