标签:cpu ++ show height blur 级联 gray nbsp ssi
前几天听到一个朋友的需求说帮人脸p马赛克有点繁琐,所以就想用Opencv做个原理。
核心原理是很简单的:
1.人脸识别
2.高斯模糊
CascadeClassifier cpufaceCascade; const string path = "../data/haarcascade_frontalface_alt.xml"; if (!cpufaceCascade.load(path)) { cout << "找不到级联器"; return -1; } Mat img = imread("../data/facetest.jpg", IMREAD_REDUCED_COLOR_8); if (img.empty()) { cout << "没有照片"; return 1; } Mat imgGray; vector<Rect> faces; cpufaceCascade.detectMultiScale(img, faces, 1.1,1,5); blur(img, imgGray,Size(20,20),Point(-1,-1),4); cout << faces.size(); if (faces.size() > 0) { for (int i = 0; i < faces.size(); i++) { if (img.channels() == 3) { for (int K = faces[i].x; K < faces[i].x + faces[i].height ; K++) { for (int J = faces[i].y; J < faces[i].y+ faces[i].width; J++) { img.at<Vec3b>(J, K) = imgGray.at<Vec3b>(J, K); } } } } } //获取一张就这些保留其他全黑的图片 namedWindow("a", WINDOW_AUTOSIZE); // 创建一个窗口 imshow("a", img); waitKey(0); destroyAllWindows(); return 0;
标签:cpu ++ show height blur 级联 gray nbsp ssi
原文地址:https://www.cnblogs.com/carsonche/p/9784474.html