OpenCV中文网站例程——鼠标绘图,图像修复

cvInpaint( const CvArr* src,const CvArr* mask,CvArr* dst, double inpaintRange, int flags )

//src:要修复的图像;
//mask:修复模板,必须是单通道图像;
//dst:目标图像;
//inpaintRange:选取邻域半径;
//flags:要使用的方法,可以是CV INPAINT NS或CV INPAINT TELEA。


程序运行时出现相关问题——

opencv里鼠标绘图程序运行一直提示error LNK2019: 无法解析的外部符号 _cvInpaint,该符号在函数 _main

其相应的解决方法——

首先 在配置属性的时候,在连接器->输入 附加依关系 中必须有opencv_photo243d.lib(我是2.4.3版本的)

其次
在……\openCV\opencv\build\include\opencv\cv.h中添加以下内容
#include "opencv2/photo/photo_c.h"
#include "opencv2/photo/photo.hpp"

最后
既可使用cvInpaint( const CvArr* src, const CvArr* mask, CvArr* dst,double inpaintRadius,int flags );


相关程序——
#ifdef _CH_
#pragma package <opencv>
#endif
 
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include"cxcore.h"
 
IplImage* inpaint_mask = 0;
IplImage* img0 = 0, *img = 0, *inpainted = 0;
CvPoint prev_pt = {-1,-1};
 
void on_mouse( int event, int x, int y, int flags, void* zhang)
{
    if( !img )
        return;
 
    if( event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
        prev_pt = cvPoint(-1,-1);
    else if( event == CV_EVENT_LBUTTONDOWN )
        prev_pt = cvPoint(x,y);
    else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
    {
        CvPoint pt = cvPoint(x,y);
        if( prev_pt.x < 0 )
            prev_pt = pt;
        cvLine( inpaint_mask, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
        cvLine( img, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
        prev_pt = pt;
        cvShowImage( "image", img );
    }
}
 
 
int main( int argc, char** argv )
{
    char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
 
    if( (img0 = cvLoadImage("E:\\shili\\Lena.jpg",-1)) == 0 )
        return 0;
 
    printf( "Hot keys: \n"
            "\tESC - quit the program\n"
            "\tr - restore the original image\n"
            "\ti or ENTER - run inpainting algorithm\n"
            "\t\t(before running it, paint something on the image)\n" );
 
    cvNamedWindow( "image", 1 );
 
    img = cvCloneImage( img0 );
    inpainted = cvCloneImage( img0 );
    inpaint_mask = cvCreateImage( cvGetSize(img), 8, 1 );
 
    cvZero( inpaint_mask );
    cvZero( inpainted );
    cvShowImage( "image", img );
    cvShowImage( "watershed transform", inpainted );
    cvSetMouseCallback( "image", on_mouse, 0 );
 
    for(;;)
    {
        int c = cvWaitKey(0);
 
        if( (char)c == 27 )
            break;
 
        if( (char)c == 'r' )
        {
            cvZero( inpaint_mask );
            cvCopy( img0, img,0 );
            cvShowImage( "image", img );
        }
 
        if( (char)c == 'i' || (char)c == '\n' )
        {
            cvNamedWindow( "inpainted image", 1 );
            cvInpaint( img, inpaint_mask, inpainted, 3, CV_INPAINT_TELEA );
            cvShowImage( "inpainted image", inpainted );
        }
    }
 
    return 1;
}


相应结果:(左边为图像修复结果,右边为鼠标绘图结果)






opencv里鼠标绘图程序运行一直提示error LNK2019: 无法解析的外部符号 _cvInpaint,该符号在函数 _main

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值