OpenCV开发之——页面效果处理(2)

一 概述

本文介绍人脸识别中的页面处理

  • 识别成功后的识别框显示与隐藏
  • 识别成功后的识别框大小调整
  • 识别成功后的图像截取

二 识别成功后的识别框显示与隐藏

2.1 识别框显示代码

for (int i = 0; i < facesArray.length; i++){
      Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
}

2.2 识别框隐藏

for (int i = 0; i < facesArray.length; i++){
      //Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
}

三 识别成功后的识别框大小调整

3.1 调整前

val facesArray = faces.toArray()

3.2 调整后

val faceList = faces.toArray().flatMap {
            listOf(it.apply {
                it.x = it.x - 70
                it.y = it.y - 70
                it.width = it.width + 70
                it.height = it.height + 70
            })
        }
for (rect in faceList) {
        Imgproc.rectangle(mRgba, rect.tl(), rect.br(), FACE_RECT_COLOR, 3)
}        

说明:

  • x坐标轴:向左移动70
  • y坐标轴:向上移动70
  • 宽度:增加70
  • 高度:增加70

四 识别成功后的图像截取

4.1 截取识别框区域

  public static boolean saveImage(Mat image, Rect rect) {
        // 原图置灰
        Mat grayMat = new Mat();
        //Imgproc.cvtColor(image, grayMat, Imgproc.COLOR_BGR2GRAY);//灰度照片
        Imgproc.cvtColor(image, grayMat, Imgproc.COLORMAP_JET);//彩色照片
        // 把检测到的人脸重新定义大小后保存成文件
        Mat sub = grayMat.submat(rect);
        Mat mat = new Mat();
        Size size = new Size(500, 500);
        Imgproc.resize(sub, mat, size);
        return Imgcodecs.imwrite(getRecFileName(), mat);

    }

4.2 截取整个屏幕区域

    public static boolean saveImage(Mat image, Rect rect) {
      return Imgcodecs.imwrite(getRecFileName(), image);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值