使用OpenCV-C++版本在CUDA下的编程应用,主要使用双边模糊,对图像进行美颜细化。
1、高斯双边模糊
int main(int argc, char** argv)
{
Mat image = imread("F:/test/face_image.jpg");
imshow("input image", image);
cuda::GpuMat image_gpu,dst;
image_gpu.upload(image);
//高斯双边模糊
cuda::bilateralFilter(image_gpu, dst, 0, 100, 15, 4);
Mat result;
dst.download(result);
imshow("result", result);
waitKey(0);
return 0;
}
原图:
模糊处理后的结果:
看上去效果还不错,脸上的坑坑洼洼都被去掉了。
当然,除了图片以外,还可以使用视频或摄像头:
void video_test_gpu()
{
VideoCapture cap(0);
Mat frame,result;
cuda::GpuMat frame_gpu,dst_gpu;
while (true)
{
double t1 = getTickCount();
cap.read(frame);
frame_gpu.upload(frame);
cuda::bilateralFilter(frame_gpu, dst_gpu, 0, 50, 10, 4);
dst_gpu.download(result);