搜索并剪切轮廓Opencv C#

时间:2019-02-27 10:34:15

标签: c# opencv

必须使用蒙版通过照片切割对象并模糊边缘。 代码以搜索边。但是模糊呢?

Mat imgGray = new Mat();    
Cv2.CvtColor(segmentationMap, imgGray, ColorConversionCodes.BGR2GRAY, 0);
Cv2.Blur(imgGray,imgGray, new Size(3,3));

Mat imgCanny = new Mat();
Cv2.Canny(imgGray,imgCanny, 2, 3);

Point[][] contours;
HierarchyIndex[] hierarchy;

Cv2.FindContours(imgCanny, out contours, out hierarchy, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);

Mat drawing  = new Mat(imgCanny.Size(), MatType.CV_8UC3);

for (int i = 0; i < contours.Length; i++)
{
     Scalar color = Scalar.Red;
     Cv2.DrawContours(drawing,contours, i, color);
}
  1. 绘制轮廓内的区域。
  2. 用面具剪
  3. 模糊边缘

面具

enter image description here

轮廓(但是由于某种原因他没有被关闭)

enter code here

0 个答案:

没有答案