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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
  • 相关阅读:
    sql中别名加as和不加as的区别
    easyui 扩展 datagrid 数据网格视图
    asp.net 版本一键升级,后台直接调用升级脚本
    SQLserver 还原数据库报“指定转换无效”的错的解决方案
    sql视图显示数据不对应
    django channels 实现实时通讯,主动推送
    django orm信号机制 + apschedule 定时任务
    django 使用原始SQL语句方式
    Django model 常用查询(搬运来备份的)
    Python3+ Django2.7开发web排坑记006 apache+wsgi部署应用
  • 原文地址:https://www.cnblogs.com/donaldlee2008/p/5236905.html
Copyright © 2011-2022 走看看