用OpenCV实现简单的泊松融合

编程入门 行业动态 更新时间:2024-10-20 08:23:41

用OpenCV实现<a href=https://www.elefans.com/category/jswz/34/1770983.html style=简单的泊松融合"/>

用OpenCV实现简单的泊松融合

原理:就不介绍了,因为我也不是很懂_。网上有很多大佬都介绍了。

opencv收集了泊松融合算法

 void seamlessClone(InputArray src, InputArray dst, InputArray mask, Point p, OutputArray blend, int flags);

参数介绍:
@param src Input 8-bit 3-channel image.
@param dst Input 8-bit 3-channel image.
@param mask Input 8-bit 1 or 3-channel image.
@param p Point in dst image where object is placed.
@param blend Output image with the same size and type as dst.
@param flags Cloning method that could be one of the following:

  • NORMAL_CLONE The power of the method is fully expressed when inserting objects with
    complex outlines into a new background
  • MIXED_CLONE The classic method, color-based selection and alpha masking might be time
    consuming and often leaves an undesirable halo. Seamless cloning, even averaged with the
    original image, is not effective. Mixed seamless cloning based on a loose selection proves
    effective.
    简单调用的代码:
  #include <time.h>#include <opencv2\opencv.hpp>void main(){clock_t start1, end1;clock_t start2, end2;cv::Mat src = cv::imread("src.jpg");cv::Mat dst = cv::imread("back.jpg ");cv::Mat src_mask = cv::imread("mask1.jpg");cv::Point center(dst.cols / 2 , dst.rows / 2);cv::Mat normal_clone;cv::Mat mixed_clone;start1 = clock();//参数:src原图,dst背景图,src_mask是mask,center是原图放到背景图哪个地方,//normal_clone是融合后的图,NORMAL_CLONE是融合的方式。seamlessClone(src, dst, src_mask, center, normal_clone, cv::NORMAL_CLONE);end1 = clock();start2 = clock();seamlessClone(src, dst, src_mask, center, mixed_clone, cv::MIXED_CLONE);//MIXED_CLONE更节省时间,大概是NORMAL_CLONE的一半时间就可以end2 = clock();printf("NORMAL_CLONE use time: %d\n", end1 - start1);printf("MIXED_CLONE use time: %d\n", end2 - start2);cv::imshow("normal_clone.jpg", normal_clone);cv::imshow("mixed_clone.jpg", mixed_clone);cv::waitKey(0);
}

原图:

背景图:
mask:

normal_clone:

mixed_clone:

NORMAL_CLONE与MIXED_CLONE的对比:

MIXED_CLONE更节省时间。效果好像都不是很好,飞机与背景图融合后,飞机的颜色都变了,参入了背景的颜色,速度也不够快,估计不能用在时时的环境下。

更多推荐

用OpenCV实现简单的泊松融合

本文发布于:2023-06-29 09:22:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/942703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!