一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

【知识点1】

把一幅图无缝融合到另一幅图里,主要是seamlessClone() 的使用。

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

注意需要三幅图合为一幅图,src与mask抠图(逻辑与,尺寸一致),把抠出的图融合到dst中的p位置处(抠出的图尺寸≤dst图)。p位置也是抠出的图的中心。

3种融合模式flags:NORMAL_CLONE = 1,MIXED_CLONE  = 2,MONOCHROME_TRANSFER = 3

复制代码
 1 #include<opencv2\opencv.hpp>
 2 #include<iostream>
 3 
 4 using namespace cv;
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     string folder = "cloning/Normal_Cloning/"; //可更换Mixed_Cloning,Monochrome_Transfer目录
10     string original_path1 = samples::findFile(folder + "source1.png");
11     string original_path2 = samples::findFile(folder + "destination1.png");
12     string original_path3 = samples::findFile(folder + "mask.png");
13 
14     Mat source = imread(original_path1, IMREAD_COLOR);
15     Mat destination = imread(original_path2, IMREAD_COLOR);
16     Mat mask = imread(original_path3, IMREAD_COLOR);
17 
18     Mat result;
19     Point p;
20     p.x = destination.size().width / 2;
21     p.y = destination.size().height / 2;
22 
23     seamlessClone(source, destination, mask, p, result, NORMAL_CLONE); //可更换MIXED_CLONE,MONOCHROME_TRANSFER
24 
25     imshow("Output", result);
26     imwrite("cloned.png", result);
27 
28     waitKey(0);
29     return 0;
30 }
复制代码

【知识点2】

对感兴趣区域进行颜色调整。如下图,花朵更鲜艳。主要是colorChange()函数的使用。

复制代码
 1 #include<opencv2\opencv.hpp>
 2 #include<iostream>
 3 
 4 using namespace cv;
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     string folder = "cloning/color_change/";
10     string original_path1 = samples::findFile(folder + "source1.png");
11     string original_path2 = samples::findFile(folder + "mask.png");
12 
13     Mat source = imread(original_path1, IMREAD_COLOR);
14     Mat mask = imread(original_path2, IMREAD_COLOR);
15 
16     Mat result;
17     colorChange(source, mask, result, 1.5, .5, .5); //mask定位source中的roi区域,调整该区域颜色r,g,b
18 
19     imshow("Output", result);
20     imwrite("cloned.png", result);
21 
22     waitKey(0);
23     return 0;
24 }
复制代码

【知识点3】

消除高亮区域,illuminationChange()函数的使用。alpha,beta两个参数共同决定消除高光后图像的模糊程度(范围0~2,0比较清晰,2比较模糊)

复制代码
 1 #include<opencv2\opencv.hpp>
 2 #include<iostream>
 3 
 4 using namespace cv;
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     string folder = "cloning/Illumination_Change/";
10     string original_path1 = samples::findFile(folder + "source1.png");
11     string original_path2 = samples::findFile(folder + "mask.png");
12 
13     Mat source = imread(original_path1, IMREAD_COLOR);
14     Mat mask = imread(original_path2, IMREAD_COLOR);
15 
16     Mat result;
17 
18     illuminationChange(source, mask, result, 0.2f, 0.4f); //消除source中mask锁定的高亮区域,后两个参数0-2调整
19 
20     imshow("Output", result);
21     imwrite("cloned.png", result);
22 
23     waitKey(0);
24     return 0;
25 }
复制代码

【知识点4】

纹理扁平化,边缘检测器选取的边缘越少(选择性越强),边缘映射就越稀疏,扁平化效果就越明显。textureFlattening()函数的使用。

复制代码
 1 #include<opencv2\opencv.hpp>
 2 #include<iostream>
 3 
 4 using namespace cv;
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     string folder = "cloning/Texture_Flattening/";
10     string original_path1 = samples::findFile(folder + "source1.png");
11     string original_path2 = samples::findFile(folder + "mask.png");
12 
13     Mat source = imread(original_path1, IMREAD_COLOR);
14     Mat mask = imread(original_path2, IMREAD_COLOR);
15 
16     Mat result;
17 
18     textureFlattening(source, mask, result, 30, 45, 3); //对mask锁定的source中的区域进行纹理扁平化,低阈值,高阈值,核尺寸
19 
20     imshow("Output", result);
21     imwrite("cloned.png", result);
22 
23     waitKey(0);
24     return 0;
25 }
复制代码

 

posted on   一杯清酒邀明月  阅读(1839)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示