opencv_dnn做人脸检测使用体验

参考: https://blog.csdn.net/qq_30815237/article/details/87914775

[问题] raw.githubusercontent.com 访问不了
sudo vim /etc/hosts
简单的说就是域名被DNS污染了
在hosts文件加上:199.232.4.133 raw.githubusercontent.com

移植到安卓

移植到安卓上参考官方
https://docs.opencv.org/3.4.1/d0/d6c/tutorial_dnn_android.html
把对应的神经网络和参数文件替换为人脸检测这个,然后检测过程参考一下就好了。

注意:
1)
deploy.prototxt(网络结构)
res10_300x300_ssd_iter_140000_fp16.caffemodel(参数)
两个文件需要放到src/main/assets下

2)
检测结果有可能超出图像,需要正确处理框

核心部分:

 // Forward image through network.
            Mat blob = Dnn.blobFromImage(image, IN_SCALE_FACTOR,
                    new Size(IN_WIDTH, IN_HEIGHT),
                    new Scalar(104.0, 117.0, 123.0), false);
            net.setInput(blob, "data");
            Mat detections = net.forward("detection_out");
            int cols = image.cols();
            int rows = image.rows();

            detections = detections.reshape(1, (int)detections.total() / 7);
            for (int i = 0; i < detections.rows(); ++i) {
     
                double confidence = detections.get(i, 2)[0];
                if (confidence > THRESHOLD) {
     
                    int classId = (int)detections.get(i, 1)[0];
                    int xLeftTop = (int)(detections.get(i, 3)[0] * cols);
                    int yLeftTop = (int)(detections.get(i, 4)[0] * rows);
                    int xRightBottom = (int)(detections.get(i, 5)[0] * cols);
                    int yRightBottom = (int)(detections.get(i, 6)[0] * rows);
                  }
                }

你可能感兴趣的:(android,AI)