1
#include "opencv2/imgcodecs.hpp"
2
#include "opencv2/highgui/highgui.hpp"
3
#include "opencv2/imgproc/imgproc.hpp"
4
#include "opencv2/photo/photo.hpp"
13
cout << "\nCool inpainging demo. Inpainting repairs damage to images by floodfilling the damage \n"
14
<< "with surrounding image areas.\n"
15
"Using OpenCV version %s\n" << CV_VERSION << "\n"
17
"./inpaint [image_name -- Default ../data/fruits.jpg]\n" << endl;
19
cout << "Hot keys: \n"
20
"\tESC - quit the program\n"
21
"\tr - restore the original image\n"
22
"\ti or SPACE - run inpainting algorithm\n"
23
"\t\t(before running it, paint something on the image)\n" << endl;
29
static void onMouse( int event, int x, int y, int flags, void* )
31
if( event == EVENT_LBUTTONUP || !(flags & EVENT_FLAG_LBUTTON) )
32
prevPt = Point(-1,-1);
33
else if( event == EVENT_LBUTTONDOWN )
35
else if( event == EVENT_MOUSEMOVE && (flags & EVENT_FLAG_LBUTTON) )
40
line( inpaintMask, prevPt, pt, Scalar::all(255), 5, 8, 0 );
41
line( img, prevPt, pt, Scalar::all(255), 5, 8, 0 );
48
int main( int argc, char** argv )
50
cv::CommandLineParser parser(argc, argv, "{help h||}{@image|../data/fruits.jpg|}");
51
if (parser.has("help"))
56
string filename = parser.get<string>("@image");
57
Mat img0 = imread(filename, -1);
60
cout << "Couldn't open the image " << filename << ". Usage: inpaint <image_name>\n" << endl;
64
namedWindow( "image", 1 );
67
inpaintMask = Mat::zeros(img.size(), CV_8U);
70
setMouseCallback( "image", onMouse, 0 );
74
char c = (char)waitKey();
81
inpaintMask = Scalar::all(0);
86
if( c == 'i' || c == ' ' )
89
inpaint(img, inpaintMask, inpainted, 3, INPAINT_TELEA);
90
imshow("inpainted image", inpainted);