opencv:图像修复inpaint函数可以编译运行,但是调用时报错。

对原图处理后调用inpaint函数便出现上图报错。

源码在编译运行时没有问题,下面会贴出来,造成报错的原因是原图的格式,我的格式是png的,只需要换一个格式为jpg的原图便可以解决这个问题。

#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/photo/photo.hpp>
#include<iostream>
using namespace cv;
using namespace std;

#define WINDOW_NAME1 "原图"
#define WINDOW_NAME2 "效果图"

static void ShowHelpText();

Mat srcImage1, inpaintMask;
Point previousPoint(-1, -1);

static void On_Mouse(int event, int x, int y, int flags, void*)
{
    if (event == EVENT_LBUTTONUP || !(flags & EVENT_FLAG_LBUTTON))
        previousPoint = Point(-1, -1);
    else if (event ==EVENT_LBUTTONDOWN)
        previousPoint = Point(x, y);
    else if (event == EVENT_MOUSEMOVE && (flags & EVENT_FLAG_LBUTTON))
    {
        Point pt(x, y);
        if (previousPoint.x < 0)
            previousPoint = pt;
        line(inpaintMask, previousPoint, pt, Scalar::all(255), 5, 8, 0);
        line(srcImage1, previousPoint, pt, Scalar::all(255), 5, 8, 0);
        previousPoint = pt;
        imshow(WINDOW_NAME1, srcImage1);
    }
}
int main(int argc, char** argv)
{
    system("color 2F");

    ShowHelpText();

    namedWindow(WINDOW_NAME1, WINDOW_NORMAL);

    //Mat srcImage = imread("F:\\vs2019文件\\图片\\小新不要舔了.png", -1);//错误的源码
    Mat srcImage = imread("F:\\vs2019文件\\图片\\3D欢呼高清图片.jpg", -1);//改正后的
    srcImage1 = srcImage.clone();
    inpaintMask = Mat::zeros(srcImage1.size(), CV_8U);
    imshow(WINDOW_NAME1, srcImage1);

    setMouseCallback(WINDOW_NAME1, On_Mouse, 0);

    while (1)
    {
        char c = (char)waitKey();

        if (c == 27)
            break;
        if (c == '2')
        {
            inpaintMask = Scalar::all(0);
            srcImage.copyTo(srcImage1);
            imshow(WINDOW_NAME1, srcImage1);
        }
        if (c == '1' || c == ' ')
        {

            namedWindow(WINDOW_NAME2, WINDOW_NORMAL);
            Mat inpaintedImage;
            inpaint(srcImage1, inpaintMask, inpaintedImage, 3, INPAINT_TELEA);
            imshow(WINDOW_NAME2, inpaintedImage);

        }
    }
    return 0;
}

static void ShowHelpText()
{

    //输出一些帮助信息
    printf("\n\n\n\t欢迎来到【图像修复】示例程序~\n");
    printf("\n\t请在进行图像修复操作之前,在【原始图】窗口中进行适量的绘制"
        "\n\n\t按键操作说明: \n\n"
        "\t\t【鼠标左键】-在图像上绘制白色线条\n\n"
        "\t\t键盘按键【ESC】- 退出程序\n\n"
        "\t\t键盘按键【1】或【SPACE】-进行图像修复操作 \n\n");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以轻松的把图片水印给去除。 Getting Started Do you have a photo where the photo would be just right if you could just remove an object or person that appears in the photo? For example, look at the following picture, which would be improved if we could just take out that observatory. Take a look at how the picture is improved when the observatory is removed. You can remove the unwanted object or person using Inpaint. Note: Before you edit your digital photos, it's a good idea to make a copy of the original image and make your edits to that copy. This way, you preserve the original image in case you need to go back to it. To remove unwanted objects in your photos Open your photo in Inpaint (on the File menu, click Open). Draw a selection around the object you wish to remove from the picture.( You can select from freehand or rectangular selection on the task pane or Select menu). After you've finished selecting the objects that you want to remove, in the task pane, click Inpaint. Inpaint will fill the selection area with intelligently generated texture drawn from the surrounding image data. (Optional) If you don't get the results you hoped for, do one of the following, and then experiment until you get just the right look: You can change area boundary which used in inpainting (rectangular area around selection, with resize handles). Hold down the SHIFT key and using the mouse try to resize or move it. For more information see remarks. Go back in your changes one step at a time, (in the task pane, click Undo last action) and try more accurate select the object you wish to remove. Or if you think selection is right, try to Inpaint it again(each inpaint procedure is unique and at the next time you've got other image). On the File menu, click Save or Save As to save your edited picture. Remarks: In some cases you need to correct area boundary which used in inpainting (rectangular area around selection, with resize handles), you need to exlude from this area part

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值