使用等高线EmguCV .net裁剪图像

时间:2018-06-05 12:35:13

标签: c# opencv image-processing crop emgucv

目前,我有一种方法可以通过查找轮廓然后勾勒出轮廓来检测图片中的文档(或大矩形)。现在我有要裁剪的矩形,如何将轮廓裁剪成新图像?

首先,我在处理过的图像中找到轮廓

CvInvoke.FindContours(img, contours, null, RetrType.Tree, ChainApproxMethod.ChainApproxSimple);

然后我循环遍历它们并将最大的一个放入这个对象:

RotatedRect box = CvInvoke.MinAreaRect(contours[i]);

然后我用它将正方形绘制到原始图像上:

CvInvoke.Polylines(img, Array.ConvertAll(box.GetVertices(), System.Drawing.Point.Round), true, new Bgr(System.Drawing.Color.DarkOrange).MCvScalar, 2);

我的问题是,如何使用EmguCV裁剪图像,而不是绘制矩形?

编辑: 我已经找到了解决方案。您可以使用:

CvInvoke.GetRectSubPix() 

传递你的RotatedRect对象和目标垫,它可以正常工作!

0 个答案:

没有答案
相关问题