• 使用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 << " Cool inpainging demo. Inpainting repairs damage to images by floodfilling the damage "
    11.             << "with surrounding image areas. "
    12.             "Using OpenCV version %s " << CV_VERSION << " "
    13.     "Usage: "
    14.         "./inpaint [image_name -- Default fruits.jpg] " << endl;
    15.     cout << "Hot keys: "
    16.         " ESC - quit the program "
    17.         " r - restore the original image "
    18.         " i or SPACE - run inpainting algorithm "
    19.         " (before running it, paint something on the image) " << 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> " << 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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
  • 相关阅读:
    软件工程实验二
    软件工程实验一
    软件工程作业--ATM自助银行服务系统
    软件工程作业—举例分析流程图与活动图的区别与联系
    第一个随笔
    机器学习 实验四 决策树算法及应用
    机器学习实验三 朴素贝叶斯算法及应用
    机器学习 实验二 K-近邻算法及应用
    飞机订票系统(文档)
    机器学习 实验一 感知器及其应用
  • 原文地址:https://www.cnblogs.com/donaldlee2008/p/5236905.html
Copyright © 2020-2023  润新知