OpenCV 4.11.0
开源计算机视觉库
加载中…
搜索中…
无匹配项
samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp

一个使用seamlessClone函数的示例

/*
* cloning_demo.cpp
*
* 作者
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
*
* 本教程演示如何在没有GUI的情况下使用OpenCV无缝克隆模块。
*
*
* 1- 普通克隆
* 2- 混合克隆
* 3- 单色转移
* 4- 颜色更改
* 5- 光照更改
* 6- 纹理平滑
* 程序以源图像和目标图像作为输入(对于方法1-3),
* 并输出克隆图像。
*
* 从github上的opencv_extra文件夹下载测试图像。
*
*/
#include "opencv2/core.hpp"
#include <iostream>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main()
{
cout << endl;
cout << "克隆模块" << endl;
cout << "---------------" << endl;
cout << "选项: " << endl;
cout << endl;
cout << "1) 普通克隆 " << endl;
cout << "2) 混合克隆 " << endl;
cout << "3) 单色转移 " << endl;
cout << "4) 局部颜色更改 " << endl;
cout << "5) 局部光照更改 " << endl;
cout << "6) 纹理平滑 " << endl;
cout << endl;
cout << "请按1-6选择上述技术: ";
int num = 1;
cin >> num;
cout << endl;
if(num == 1)
{
string folder = "cloning/Normal_Cloning/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "destination1.png";
string original_path3 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat destination = imread(original_path2, IMREAD_COLOR);
Mat mask = imread(original_path3, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(destination.empty())
{
cout << "无法加载目标图像 " << original_path2 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path3 << endl;
exit(0);
}
Mat result;
Point p;
p.x = 400;
p.y = 100;
seamlessClone(source, destination, mask, p, result, 1);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
else if(num == 2)
{
string folder = "cloning/Mixed_Cloning/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "destination1.png";
string original_path3 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat destination = imread(original_path2, IMREAD_COLOR);
Mat mask = imread(original_path3, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(destination.empty())
{
cout << "无法加载目标图像 " << original_path2 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path3 << endl;
exit(0);
}
Mat result;
Point p;
p.x = destination.size().width/2;
p.y = destination.size().height/2;
seamlessClone(source, destination, mask, p, result, 2);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
else if(num == 3)
{
string folder = "cloning/Monochrome_Transfer/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "destination1.png";
string original_path3 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat destination = imread(original_path2, IMREAD_COLOR);
Mat mask = imread(original_path3, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(destination.empty())
{
cout << "无法加载目标图像 " << original_path2 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path3 << endl;
exit(0);
}
Mat result;
Point p;
p.x = destination.size().width/2;
p.y = destination.size().height/2;
seamlessClone(source, destination, mask, p, result, 3);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
else if(num == 4)
{
string folder = "cloning/Color_Change/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat mask = imread(original_path2, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path2 << endl;
exit(0);
}
Mat result;
colorChange(source, mask, result, 1.5, .5, .5);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
else if(num == 5)
{
string folder = "cloning/Illumination_Change/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat mask = imread(original_path2, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path2 << endl;
exit(0);
}
Mat result;
illuminationChange(source, mask, result, 0.2f, 0.4f);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
else if(num == 6)
{
string folder = "cloning/Texture_Flattening/";
string original_path1 = folder + "source1.png";
string original_path2 = folder + "mask.png";
Mat source = imread(original_path1, IMREAD_COLOR);
Mat mask = imread(original_path2, IMREAD_COLOR);
if(source.empty())
{
cout << "无法加载源图像 " << original_path1 << endl;
exit(0);
}
if(mask.empty())
{
cout << "无法加载蒙版图像 " << original_path2 << endl;
exit(0);
}
Mat result;
textureFlattening(source, mask, result, 30, 45, 3);
imshow("输出",result);
imwrite(folder + "cloned.png", result);
}
waitKey(0);
}
N维密集数组类
**定义:** mat.hpp:829
MatSize size
**定义:** mat.hpp:2177
bool empty() const
如果数组没有元素,则返回true。
_Tp y
点的y坐标
**定义:** types.hpp:202
_Tp x
点的x坐标
**定义:** types.hpp:201
int main(int argc, char *argv[])
**定义:** highgui_qt.cpp:3
**定义:** core.hpp:107
STL 命名空间。