人脸滤镜-几何变换简单代码

人脸几何滤镜主要是根据简单的几何变换公式,实现对图像的扭曲,达到类似哈哈镜的娱乐目的,具体代码如下,很简单:

int test_func() 
{
	cv::Mat src_img = cv::imread("test.jpg");
	float coe = 150.0;
	cv::Mat res_img;
	cv::Point cen_pnt(239, 364);
	sphere_trans(src_img, cen_pnt, coe, res_img);

	return 0;
}

int sphere_trans(cv::Mat&src_img, cv::Point&cen_pnt, float coe, cv::Mat&res_img) 
{
	if (src_img.empty() || cen_pnt.x<0 || cen_pnt.y<0 
		|| cen_pnt.x>src_img.cols || cen_pnt.y>src_img.rows)
		return -1;


	res_img = cv::Mat(src_img.size(), CV_8UC3, cv::Scalar(0, 0, 0));


	for (int i=0;i= res_img.cols)
				res_x = res_img.cols - 1;

			if (res_y < 0)
				res_y = 0;

			if (res_y >= res_img.rows)
				res_y = res_img.rows - 1;


			res_img.at(j,i) = src_img.at(res_y, res_x);

		}
	}


	cv::imshow("result", res_img);
	cv::waitKey(0);

	return 0;
}

你可能感兴趣的:(人脸美颜)