问题描述:
Ø
蓝屏抠图
建立一个纯色背景(如蓝色或绿色),先拍摄一幅空背景图像,再在背景前拍摄一幅自己的图像,尝试将两幅图像的对应像素相减并去噪,实现人像的抠图处理。
C++代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
//读入图片
Mat img1 = imread("背景.jpg");
Mat img2 = imread("图片.jpg");
Mat img_result1, img_result2;
//相减
subtract(img1,img2, img_result1);
subtract(img2,img1, img_result2);
//中值滤波
Mat mf1(img_result1.size(),img_result1.type());
medianBlur(img_result1,mf1,3);
Mat mf2(img_result2.size(),img_result2.type());
medianBlur(img_result2,mf2,3);
//显示
imshow("result1",img_result1);
imshow("result2",img_result2);
waitKey();
return 0;
}
背景(没有蓝色背景,就用实验室红色鼠标垫充当啦
):
图片:
处理结果: