EmguCV提取轮廓的一个例子

来源:互联网 发布:淘宝自动回复经典语句 编辑:程序博客网 时间:2024/06/05 17:21

EmguCV, 也就是OpenCV的C#版本,用法也和OpenCV一致:

using System.Drawing;using Emgu.CV;using Emgu.CV.Structure;using Emgu.CV.CvEnum;using Emgu.CV.Util;public class EmguDemo{    private List<Rectangle> _rcList = new List<Rectangle>();    public void GetRects(ref Bitmap bmp, int thresholdBinary)    {        _grayImage = new Image<Gray, byte>(bmp);        Image<Gray, byte> binaryImage = _grayImage.ThresholdBinary(new Gray(thresholdBinary), new Gray(255));        VectorOfVectorOfPoint contour = new VectorOfVectorOfPoint();        CvInvoke.FindContours(binaryImage, contour, null, RetrType.External, ChainApproxMethod.ChainApproxSimple);        CvInvoke.ApproxPolyDP(contour, contour, 1.0, true);        _rcList.Clear();        for (int i = 0; i < contour.Size; i++)        {            _rcList.Add(CvInvoke.BoundingRectangle(contour[i]));        }        // do something you want...    }}
0 0
原创粉丝点击