在openCV中删除图像的特定部分 [英] Removing specific parts of the image in openCV

查看:60
本文介绍了在openCV中删除图像的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些图像处理,需要在图像中执行以下任务::

I am doing some image processing and need to do the following task in images ::

图片

从这里开始,我要去除眼睛,眉毛,嘴唇等,以免图像的平滑度下降(例如,如果去除眼睛,则该区域应替换为相邻的颜色).

From here I want to remove eyes, eyebrows, lips etc such that the smoothness of the image is not lost (eg, if the eyes are removed then the area should be replaced with neighboring colors).

我有需要平整的部分(眼睛等)的区域的细节(点).如下所示:

I have the details(Points) of the area covering the part that needs to be flatten(eyes etc).Shown below::

推荐答案

如果您已经有了要替换的点或什至更好的轮廓(例如第二张图中以绿色绘制的轮廓),请查看inpaint : http://docs.opencv.org/3.1.0/d1/d0d/group__photo.html#gaedd30dfa0214fec4c88138b51d678085

If you already have the points or even better contours you want to replace (like these drawn in green in your 2nd image), have a look at inpaint: http://docs.opencv.org/3.1.0/d1/d0d/group__photo.html#gaedd30dfa0214fec4c88138b51d678085

我认为这正是您要寻找的!参见此处的示例: https://en.wikipedia.org/wiki/Inpainting

I think this is exactly what you are looking for! See here for an example: https://en.wikipedia.org/wiki/Inpainting

过程非常简单:

  1. 制作一个填充有轮廓( drawContours ,厚度: CV_FILLED )的蒙版,以对其各自的环境进行修补/替换.
  2. inpaint (带有此蒙版).
  1. Make a mask filled with your contours (drawContours, thickness: CV_FILLED) to be inpainted/replaced with their respective environment and
  2. inpaint with this mask.

我应该提到,这仅适用于8bit图像.

I should mention that this does only work with 8bit-images.

下面的(未经测试的)代码段应该可以实现.

The following (untested) code snippet should do it.

Mat mask = Mat::zeros(img.size(), CV_8UC1);
for (int i = 0; i < contours.size(); i++)
  drawContours(mask, contours, i, Scalar::all(255), CV_FILLED);
Mat dst;
double radius = 20;    
inpaint(img, mask, dst, radius, INPAINT_NS);
//inpaint(img, mask, dst, radius, INPAINT_TELEA);
imshow("dst", dst);
waitKey();

要绘制几个点的轮廓,请执行以下操作:轮廓只是点的向量,打包成另一个向量.因此,对于给定的 vector< Point> ;,解决方案应该是这样的.点.

To make a contour of a couple of points: A contour is just a vector of points, packed into another vector. So, the solution should be something like this with a given vector<Point> points.

vector<vector<Point> > contours;
contours.push_back(points);
drawContours(mask, contours, 0, Scalar::all(255), CV_FILLED);

这篇关于在openCV中删除图像的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆