Java OpenCV-检测ROI,创建子垫并复​​制到原始垫 [英] Java OpenCV - detecting ROI, creating submat and copy to original mat

查看:162
本文介绍了Java OpenCV-检测ROI,创建子垫并复​​制到原始垫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使网络摄像头检测到的所有人的脸部模糊. 问题在于,当网络摄像头检测到面部时,程序会显示带有模糊面部的裁切垫.

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

没有人脸检测

具有面部检测功能

推荐答案

使用Mat的此构造函数

use this constructor of Mat

Mat imageROI = new Mat(grayFrame,rectCrop);

代替

 Mat imageROI = grayFrame.submat(rectCrop);

构造函数为您提供了GrayFrame拥有的数据矩阵的引用.因此对submat的任何修改都会影响bigmat.submat给出了裁剪矩形的grayFrame数据矩阵的副本.因此,对子垫的修改不会影响bigmat.

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.

这篇关于Java OpenCV-检测ROI,创建子垫并复​​制到原始垫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆