zoukankan      html  css  js  c++  java
  • 使用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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
  • 相关阅读:
    vue3.0基本使用
    node 版本升级
    Steam游戏《Northgard(北境之地)》修改器制作
    万能WEB弹出框,js随意适配
    数据湖了解
    操作系统(一)
    无题
    基于林业害虫识别系统的缺陷分析
    美化Android下拉刷新
    软件测试
  • 原文地址:https://www.cnblogs.com/donaldlee2008/p/5236905.html
Copyright © 2011-2022 走看看