seamlessClone是OpenCV中新出现的函数,应该说如果能够基于较为准确的图像分割,能够得到很好的结果。
原始的前景,背景
三种flag下的融合结果
//注意头文件中添加 #include <opencv2/photo.hpp>
int main( int argc, const char** argv )
{
Mat src = imread("iloveyoupapa.png");
Mat dst = imread("wood.png");
// Create an all white mask
Mat src_mask = 255 * Mat::ones(src.rows, src.cols, src.depth());
// The location of the center of the src in the dst
Point center(dst.cols/2,dst.rows/2);
// Seamlessly clone src into dst and put the results in output
Mat normal_clone;
Mat mixed_clone;
Mat monochrome_clone;
seamlessClone(src, dst, src_mask, center, normal_clone, NORMAL_CLONE);
seamlessClone(src, dst, src_mask, center, mixed_clone, MIXED_CLONE);
seamlessClone(src, dst, src_mask, center, monochrome_clone, MONOCHROME_TRANSFER);
imshow("normal_clone",normal_clone);
imshow("minxed_clone",mixed_clone);
imshow("monochrome_clone",monochrome_clone);
imshow("wood",dst);
imshow("lovepapa",src);
waitKey();
return 0;
}
{
Mat src = imread("iloveyoupapa.png");
Mat dst = imread("wood.png");
// Create an all white mask
Mat src_mask = 255 * Mat::ones(src.rows, src.cols, src.depth());
// The location of the center of the src in the dst
Point center(dst.cols/2,dst.rows/2);
// Seamlessly clone src into dst and put the results in output
Mat normal_clone;
Mat mixed_clone;
Mat monochrome_clone;
seamlessClone(src, dst, src_mask, center, normal_clone, NORMAL_CLONE);
seamlessClone(src, dst, src_mask, center, mixed_clone, MIXED_CLONE);
seamlessClone(src, dst, src_mask, center, monochrome_clone, MONOCHROME_TRANSFER);
imshow("normal_clone",normal_clone);
imshow("minxed_clone",mixed_clone);
imshow("monochrome_clone",monochrome_clone);
imshow("wood",dst);
imshow("lovepapa",src);
waitKey();
return 0;
}
当然选择这个例子有些讨巧的存在,因为前景为白底红色的文字,这个时候还是比较好进行区分的。同时我还做了一些其他图片的实验。
使用蝴蝶和星空来进行融合