算法学习|opencv人像(人脸)美颜、磨皮

#include #include #include #include using namespace std; using namespace cv; void whiteFace(Mat& matSelfPhoto, int alpha, int beta) { for (int y = 0; y < matSelfPhoto.rows; y++) { for (int x = 0; x < matSelfPhoto.cols; x++) { for (int c = 0; c < 3; c++) { matSelfPhoto.at(y, x)[c] = saturate_cast(alpha*(matSelfPhoto.at(y, x)[c]) + beta); } } } }int main() { Mat matResult; Mat src = https://www.it610.com/article/imread("E:/rengong_check/face/2_face.jpg"); int bilateralFilterVal = 30; // 双边模糊系数 imshow("src", src); whiteFace(src, 1.2, 20); // 调整对比度与亮度,参数2为对比度,参数3为亮度 imshow("white_src", src); GaussianBlur(src, src, Size(3, 3), 0, 0); // 高斯模糊,消除椒盐噪声 imshow("gaussian_src", src); bilateralFilter(src, matResult, bilateralFilterVal, // 整体磨皮 bilateralFilterVal * 2, bilateralFilterVal / 2); imshow("bilateralFilter_src", matResult); Mat matFinal; // 图像增强,使用非锐化掩蔽(Unsharpening Mask)方案。 cv::GaussianBlur(matResult, matFinal, cv::Size(0, 0), 3); cv::addWeighted(matResult, 1.5, matFinal, -0.5, 0, matFinal); imshow("inforcement_src", matFinal); //imwrite("E:\\test\\result.png", matFinal); waitKey(0); return 0; }

【算法学习|opencv人像(人脸)美颜、磨皮】算法学习|opencv人像(人脸)美颜、磨皮
文章图片

    推荐阅读