http://www.opencv.org.cn/forum.php?mod=viewthread&tid=33151
- #include "stdafx.h"
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- #include "opencv2/photo/photo.hpp"
- #include <iostream>
- using namespace cv;
- using namespace std;
- static void help()
- {
- cout << "
Cool inpainging demo. Inpainting repairs damage to images by floodfilling the damage
"
- << "with surrounding image areas.
"
- "Using OpenCV version %s
" << CV_VERSION << "
"
- "Usage:
"
- "./inpaint [image_name -- Default fruits.jpg]
" << endl;
- cout << "Hot keys:
"
- " ESC - quit the program
"
- " r - restore the original image
"
- " i or SPACE - run inpainting algorithm
"
- " (before running it, paint something on the image)
" << endl;
- }
- Mat img, inpaintMask;
- Point prevPt(-1,-1);
- static void onMouse( int event, int x, int y, int flags, void* )
- {
- if( event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
- prevPt = Point(-1,-1);
- else if( event == CV_EVENT_LBUTTONDOWN )
- prevPt = Point(x,y);
- else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
- {
- Point pt(x,y);
- if( prevPt.x < 0 )
- prevPt = pt;
- line( inpaintMask, prevPt, pt, Scalar::all(255), 5, 8, 0 );
- line( img, prevPt, pt, Scalar::all(255), 5, 8, 0 );
- prevPt = pt;
- imshow("image", img);
- }
- }
- int main( int argc, char** argv )
- {
- //读取图像和mask图像
- char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
- Mat img0 = imread(filename, -1);
- if(img0.empty())
- {
- cout << "Couldn't open the image " << filename << ". Usage: inpaint <image_name>
" << endl;
- return 0;
- }
-
- namedWindow( "image", 1 );
- img = img0.clone();
-
- imshow("image", img);
- Mat inpaintMask = imread("mask.jpg", 0);
- imshow("mask",inpaintMask);
- Mat inpainted;
- //注意这个inpaintmask的
- inpaint(img, inpaintMask, inpainted, 3, CV_INPAINT_TELEA);
- imshow("inpainted image", inpainted);
- cv::waitKey();
- return 0;
- }
复制代码
<ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op>
|
|
|