OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp

使用 seamlessClone 函式的示例

/*
* cloning_demo.cpp
*
* 作者
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
*
* 本教程演示如何使用 OpenCV 無縫克隆
* 模組,無需 GUI。
*
* 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:830
MatSize size
定義 mat.hpp:2187
cv::getTickFrequency
double getTickFrequency()
_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 名稱空間。