使用inpaint例子,去除水印

http://www.opencv.org.cn/forum.php?mod=viewthread&tid=33151

 

  1. #include "stdafx.h"
  2. #include "opencv2/highgui/highgui.hpp"
  3. #include "opencv2/imgproc/imgproc.hpp"
  4. #include "opencv2/photo/photo.hpp"
  5. #include <iostream>
  6. using namespace cv;
  7. using namespace std;
  8. static void help()
  9. {
  10.     cout << "\nCool inpainging demo. Inpainting repairs damage to images by floodfilling the damage \n"
  11.             << "with surrounding image areas.\n"
  12.             "Using OpenCV version %s\n" << CV_VERSION << "\n"
  13.     "Usage:\n"
  14.         "./inpaint [image_name -- Default fruits.jpg]\n" << endl;
  15.     cout << "Hot keys: \n"
  16.         "\tESC - quit the program\n"
  17.         "\tr - restore the original image\n"
  18.         "\ti or SPACE - run inpainting algorithm\n"
  19.         "\t\t(before running it, paint something on the image)\n" << endl;
  20. }
  21. Mat img, inpaintMask;
  22. Point prevPt(-1,-1);
  23. static void onMouse( int event, int x, int y, int flags, void* )
  24. {
  25.     if( event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
  26.         prevPt = Point(-1,-1);
  27.     else if( event == CV_EVENT_LBUTTONDOWN )
  28.         prevPt = Point(x,y);
  29.     else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
  30.     {
  31.         Point pt(x,y);
  32.         if( prevPt.x < 0 )
  33.             prevPt = pt;
  34.         line( inpaintMask, prevPt, pt, Scalar::all(255), 5, 8, 0 );
  35.         line( img, prevPt, pt, Scalar::all(255), 5, 8, 0 );
  36.         prevPt = pt;
  37.         imshow("image", img);
  38.     }
  39. }
  40. int main( int argc, char** argv )
  41. {        
  42.         //读取图像和mask图像
  43.     char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
  44.     Mat img0 = imread(filename, -1);
  45.     if(img0.empty())
  46.     {
  47.         cout << "Couldn't open the image " << filename << ". Usage: inpaint <image_name>\n" << endl;
  48.         return 0;
  49.     }
  50.     
  51.     namedWindow( "image", 1 );
  52.     img = img0.clone();
  53.   
  54.     imshow("image", img);
  55.         Mat inpaintMask = imread("mask.jpg", 0);
  56.         imshow("mask",inpaintMask);     
  57.               Mat inpainted;
  58.                           //注意这个inpaintmask的
  59.               inpaint(img, inpaintMask, inpainted, 3, CV_INPAINT_TELEA);
  60.               imshow("inpainted image", inpainted);
  61.     cv::waitKey();
  62.     return 0;
  63. }
复制代码
<ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op> 

 
 
 
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
posted @ 2016-03-02 23:09  donaldlee  阅读(1544)  评论(0编辑  收藏  举报