对OpenCV中seamlessClone的初步实验
Posted GreenOpen专注图像处理
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对OpenCV中seamlessClone的初步实验相关的知识,希望对你有一定的参考价值。
seamlessClone是OpenCV中新出现的函数,应该说如果能够基于较为准确的图像分割,能够得到很好的结果。
原始的前景,背景![](https://image.cha138.com/20210608/6a57f2edd0254a6ea707f73dc95108d8.jpg)
![](https://image.cha138.com/20210608/ccbd45b9f07442558bb5ec41037e858a.jpg)
![](https://image.cha138.com/20210608/6a57f2edd0254a6ea707f73dc95108d8.jpg)
![](https://image.cha138.com/20210608/ccbd45b9f07442558bb5ec41037e858a.jpg)
三种flag下的融合结果
![](https://image.cha138.com/20210608/8150377a32d542ebba17ce6158b202d7.jpg)
//注意头文件中添加 #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;
}
当然选择这个例子有些讨巧的存在,因为前景为白底红色的文字,这个时候还是比较好进行区分的。同时我还做了一些其他图片的实验。
使用蝴蝶和星空来进行融合
![](https://image.cha138.com/20210608/bf8aa4533aaa4dfda33c4705408bca7c.jpg)
![](https://image.cha138.com/20210608/32d1c0158e944ad0a0cd7003e631d513.jpg)
以上是关于对OpenCV中seamlessClone的初步实验的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV 无缝融合seamlessClone(),colorChange(),illuminationChange(),textureFlattening()