尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
【opencv】Opencv python: seamlessClone泊松融合 (我把Lena变成了彼岸花怪/(ㄒoㄒ)/~~)
为什么要进行融合呢原因是LZ在进行贴图操作的时候经常会出现很明显的边界效应在各种查找资料的情况下找到了一种比较适合图像融合的方法并且OpenCV有对应的接口所以就网上下了图片做了一些尝试当然最后并没有使用这个函数是因为贴图效果太不明显了LZ甚至以为是自己代码写错了所以这个函数因人而异。首先这个函数的用法defseamlessClone(src,dst,mask,p,flags,blendNone):# real signature unknown; restored from __doc__ seamlessClone(src, dst, mask, p, flags[, blend]) - blend . brief Image editing tasks concern either global changes (color/intensity corrections, filters, . deformations) or local changes concerned to a selection. Here we are interested in achieving local . changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless . manner. The extent of the changes ranges from slight distortions to complete replacement by novel . content cite PM03 . . . 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 cv::NORMAL_CLONE, cv::MIXED_CLONE or cv::MONOCHROME_TRANSFER passNORMAL_CLONEPython: cv.NORMAL_CLONEThe power of the method is fully expressed when inserting objects with complex outlines into a new background将具有复杂轮廓的对象插入新背景也就是说不保留dst 图像的texture细节目标区域的梯度只由源图像决定。MIXED_CLONEPython: cv.MIXED_CLONEThe 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.基于宽松选择的混合无缝克隆保留des图像的texture 细节。目标区域的梯度是由原图像和目的图像的组合计算出来(计算dominat gradient)。MONOCHROME_TRANSFERPython: cv.MONOCHROME_TRANSFERMonochrome transfer allows the user to easily replace certain features of one object by alternative features.不保留src图像的颜色细节只有src图像的质地颜色和目标图像一样可以用来进行皮肤质地填充美颜是不是可以用呢importcv2importnumpyasnp# read our test imgesimg1cv2.imread(../test_imgs/lena_standard.jpg)img2cv2.imread(../test_imgs/beiji.jpeg)cv2.imshow(img1,img1)cv2.imshow(img2,img2)cv2.waitKey()cv2.destroyAllWindows()# create an white maskmask255*np.ones(img1.shape,img1.dtype)# the location of the src in the dstwidth,height,channelimg2.shape center(int(height/2),int(width/2))normal_clonecv2.seamlessClone(img1,img2,mask,center,cv2.NORMAL_CLONE)cv2.imshow(normal_clone,normal_clone)cv2.waitKey()mixed_clonecv2.seamlessClone(img1,img2,mask,center,cv2.MIXED_CLONE)cv2.imshow(mixed_clone,mixed_clone)cv2.waitKey()# cv2.destroyAllWindows()mono_clonecv2.seamlessClone(img1,img2,mask,center,cv2.MONOCHROME_TRANSFER)cv2.imshow(mono_clone,mono_clone)cv2.waitKey()cv2.destroyAllWindows()额测试图片感觉没选好融合起来感觉哪里怪怪的/(ㄒoㄒ)/~~#这段代码写的可随意了就是生成一个mask做一个融合img1_graycv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)ret,binarycv2.threshold(img1_gray,100,255,cv2.THRESH_BINARY|cv2.THRESH_TRIANGLE)contours,_cv2.findContours(binary,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)# print(contour: , contour)src_masknp.zeros(img1.shape,img1.dtype)area[]want_area[]foriinrange(len(contours)):area.append(cv2.contourArea(contours[i]))area.sort()foriinrange(len(contours)):if(cv2.contourArea(contours[i])area[-1]):cv2.fillConvexPoly(src_mask,contours[i],0)else:cv2.fillConvexPoly(src_mask,contours[i],(255,255,255))test_masksrc_mask[:,:,1]# print(mask_shape: , mask_new.shape)normal_clone_bincv2.seamlessClone(img1,img2,test_mask,center,cv2.NORMAL_CLONE)cv2.imshow(normal_clone_bin,normal_clone_bin)cv2.waitKey()cv2.destroyAllWindows()参考地址https://www.jianshu.com/p/49adfbe4b804https://docs.opencv.org/3.4/df/da0/group__photo__clone.html
RELATED

相关推荐

【c++】c语言入门到c++使用高手: c语言入门之函数(二)

【c++】c语言入门到c++使用高手: c语言入门之函数(二)

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/10/23 5:51:47
【c++】c语言入门到c++使用高手: c语言入门之编译预处理(二)

【c++】c语言入门到c++使用高手: c语言入门之编译预处理(二)

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/10/23 5:51:47
【c++】c语言入门到c++使用高手: c语言入门之函数(四)

【c++】c语言入门到c++使用高手: c语言入门之函数(四)

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/10/23 5:51:47
MORE NEWS

更多资讯

📰

ESP32 CSI 快速上手指南:用两块开发板跑通 Wi-Fi 感知链路

ESP32 CSI 快速上手指南:用两块开发板跑通 Wi-Fi 感知链路 【免费下载链接】esp-csi Applications based on Wi-Fi CSI (Channel state information), such as indoor positioning, human detection 项目地址: https://gitcode.com/GitHub_Trending/es/esp-csi …

📰

python把pdf中所有页面导出为图片

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📰

Rime 输入法怎么挑:5 分钟看懂 awesome-rime 输入方案与配置列表

Rime 输入法怎么挑:5 分钟看懂 awesome-rime 输入方案与配置列表 【免费下载链接】awesome-rime A curated list of Rime IME schemata and configs | Rime 輸入方案和配置列表 项目地址: https://gitcode.com/GitHub_Trending/aw/awesome-rime 拼音打字总是…

📰

freehire 按用户 LLM 花费归因:`internal/ai/llmkey` 的密钥铸造、解析与回收机制

【免费下载链接】freehire freehire — the open-source search engine for job seekers 项目地址: https://gitcode.com/GitHub_Trending/fr/freehire 点击查看 免费下载 导读 freehire 的每一次模型调用最终都会落到某个 LLM 网关的凭证上。要让"谁花了多少…

📰

YimMenu 完整指南:GTA5 防崩溃菜单的功能、编译与 Lua 扩展教程

YimMenu 完整指南:GTA5 防崩溃菜单的功能、编译与 Lua 扩展教程 【免费下载链接】YimMenu YimMenu, a GTA V menu protecting against a wide ranges of the public crashes and improving the overall experience. 项目地址: https://gitcode.com/GitHub_Trendin…

📰

agents-md - SKILL

name: agents-md description: This skill should be used when the user asks to “create AGENTS.md”, “update AGENTS.md”, “maintain agent docs”, “set up CLAUDE.md”, or needs to keep agent instructions concise. Enforces research-backed best practices for…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬