inpaint()不会产生预期的结果。为什么?

时间:2017-08-28 11:21:12

标签: c++ opencv opencv3.2

我试图消除眩光。

这是我原来的形象 enter image description here

这是我的面具图像 enter image description here

我使用以下代码行来使用inpaint()

inpaint(image, vthresh, out, 5.0, CV_INPAINT_NS); //CV_INPAINT_TELEA , CV_INPAINT_NS

但我不明白为什么我不能使用inpaint()获得任何效果。 任何人都可以指出原因吗?谢谢!

1 个答案:

答案 0 :(得分:3)

你走了:

#include "opencv2/highgui.hpp"
#include "opencv2/photo.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int main(int args, char** argv)
{
   //Read the image
   Mat img = imread("/Desktop/apple.png", -1);
   //create inpaint mask the size of original image
   Mat inpaintMask = img.clone();
   //convert mask from rgb to gray
   cv::cvtColor(inpaintMask, inpaintMask, cv::COLOR_RGB2GRAY);
   // convert mask from gray to binary by thresholding, you can play with 170 and 255 args to achieve desired mask
   cv::threshold(inpaintMask, inpaintMask, 170, 255, cv::THRESH_BINARY);
   Mat inpainted;
   //finally call inpaint function and pass the args
   inpaint(img, inpaintMask, inpainted, 3, INPAINT_TELEA);

   imshow("image", img);
   imshow("mask", inpaintMask);
   imshow("inpainted image", inpainted);
   cv::waitKey(0);
}

编辑:添加标题和主要功能,使其成为独立文件