@ -17,8 +17,7 @@
* The program takes as input a source and a destination image ( for 1 - 3 methods )
* The program takes as input a source and a destination image ( for 1 - 3 methods )
* and outputs the cloned image .
* and outputs the cloned image .
*
*
* Download test images from opencv_extra folder @ github .
* Download test images from opencv_extra repository .
*
*/
*/
# include "opencv2/photo.hpp"
# include "opencv2/photo.hpp"
@ -27,7 +26,6 @@
# include "opencv2/highgui.hpp"
# include "opencv2/highgui.hpp"
# include "opencv2/core.hpp"
# include "opencv2/core.hpp"
# include <iostream>
# include <iostream>
# include <stdlib.h>
using namespace std ;
using namespace std ;
using namespace cv ;
using namespace cv ;
@ -35,6 +33,7 @@ using namespace cv;
int main ( )
int main ( )
{
{
cout < < endl ;
cout < < endl ;
cout < < " Note: specify OPENCV_SAMPLES_DATA_PATH_HINT=<opencv_extra>/testdata/cv " < < endl < < endl ;
cout < < " Cloning Module " < < endl ;
cout < < " Cloning Module " < < endl ;
cout < < " --------------- " < < endl ;
cout < < " --------------- " < < endl ;
cout < < " Options: " < < endl ;
cout < < " Options: " < < endl ;
@ -54,9 +53,9 @@ int main()
if ( num = = 1 )
if ( num = = 1 )
{
{
string folder = " cloning/Normal_Cloning/ " ;
string folder = " cloning/Normal_Cloning/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " destination1.png " ;
string original_path2 = samples : : findFile ( folder + " destination1.png " ) ;
string original_path3 = folder + " mask.png " ;
string original_path3 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
@ -86,14 +85,14 @@ int main()
seamlessClone ( source , destination , mask , p , result , 1 ) ;
seamlessClone ( source , destination , mask , p , result , 1 ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
}
else if ( num = = 2 )
else if ( num = = 2 )
{
{
string folder = " cloning/Mixed_Cloning/ " ;
string folder = " cloning/Mixed_Cloning/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " destination1.png " ;
string original_path2 = samples : : findFile ( folder + " destination1.png " ) ;
string original_path3 = folder + " mask.png " ;
string original_path3 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
@ -123,14 +122,14 @@ int main()
seamlessClone ( source , destination , mask , p , result , 2 ) ;
seamlessClone ( source , destination , mask , p , result , 2 ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
}
else if ( num = = 3 )
else if ( num = = 3 )
{
{
string folder = " cloning/Monochrome_Transfer/ " ;
string folder = " cloning/Monochrome_Transfer/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " destination1.png " ;
string original_path2 = samples : : findFile ( folder + " destination1.png " ) ;
string original_path3 = folder + " mask.png " ;
string original_path3 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
Mat destination = imread ( original_path2 , IMREAD_COLOR ) ;
@ -160,13 +159,13 @@ int main()
seamlessClone ( source , destination , mask , p , result , 3 ) ;
seamlessClone ( source , destination , mask , p , result , 3 ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
}
else if ( num = = 4 )
else if ( num = = 4 )
{
{
string folder = " cloning/Color_C hange/ " ;
string folder = " cloning/color_c hange/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " mask.png " ;
string original_path2 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
@ -187,13 +186,13 @@ int main()
colorChange ( source , mask , result , 1.5 , .5 , .5 ) ;
colorChange ( source , mask , result , 1.5 , .5 , .5 ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
}
else if ( num = = 5 )
else if ( num = = 5 )
{
{
string folder = " cloning/Illumination_Change/ " ;
string folder = " cloning/Illumination_Change/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " mask.png " ;
string original_path2 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
@ -214,13 +213,13 @@ int main()
illuminationChange ( source , mask , result , 0.2f , 0.4f ) ;
illuminationChange ( source , mask , result , 0.2f , 0.4f ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
}
else if ( num = = 6 )
else if ( num = = 6 )
{
{
string folder = " cloning/Texture_Flattening/ " ;
string folder = " cloning/Texture_Flattening/ " ;
string original_path1 = folder + " source1.png " ;
string original_path1 = samples : : findFile ( folder + " source1.png " ) ;
string original_path2 = folder + " mask.png " ;
string original_path2 = samples : : findFile ( folder + " mask.png " ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat source = imread ( original_path1 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
Mat mask = imread ( original_path2 , IMREAD_COLOR ) ;
@ -241,7 +240,12 @@ int main()
textureFlattening ( source , mask , result , 30 , 45 , 3 ) ;
textureFlattening ( source , mask , result , 30 , 45 , 3 ) ;
imshow ( " Output " , result ) ;
imshow ( " Output " , result ) ;
imwrite ( folder + " cloned.png " , result ) ;
imwrite ( " cloned.png " , result ) ;
}
else
{
cerr < < " Invalid selection: " < < num < < endl ;
exit ( 1 ) ;
}
}
waitKey ( 0 ) ;
waitKey ( 0 ) ;
}
}