首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EmguCV snake函数

EmguCV snake函数
EN

Stack Overflow用户
提问于 2014-03-28 05:48:18
回答 1查看 2.1K关注 0票数 1

我正在尝试使用EmguCV中的snake活动轮廓,但我不认为anything.Here是我的代码:

代码语言:javascript
复制
     Image<Gray, Byte> img = new Image<Gray, Byte>(300, 300, new Gray());

     Point center = new Point(100, 100);
     double width = 20;
     double height = 40;
     Rectangle rect = new Rectangle(center, new Size(20, 20));
     img.Draw(rect, new Gray(255.0), -1);

     using (MemStorage stor = new MemStorage())
     {
        Seq<Point> pts = new Seq<Point>((int)SEQ_TYPE.CV_SEQ_POLYGON, stor);
        pts.Push(new Point(20, 20));
        pts.Push(new Point(20, 280));
        pts.Push(new Point(280, 280));
        pts.Push(new Point(280, 20));

        //Image<Gray, Byte> canny = img.Canny(100.0, 40.0);
        Seq<Point> snake = img.Snake(pts, 0.1f, 0.5f, 0.4f, new Size(21, 21), new MCvTermCriteria(500, 0.1), stor);

        img.Draw(pts, new Gray(120), 1);
        img.Draw(snake, new Gray(80), 2);

我做错了什么?你知道吗?

EN

回答 1

Stack Overflow用户

发布于 2014-03-28 23:47:12

你没有画出你的初始点。

我已经为你和整个社区设置了一些代码,因为那里没有emgu蛇的样本。

代码语言:javascript
复制
        private void TestSnake()
    {
        Image<Gray, Byte> grayImg = new Image<Gray, Byte>(400, 400, new Gray());
        Image<Bgr, Byte> img = new Image<Bgr, Byte>(400, 400, new Bgr(255,255,255));

        // draw an outer circle on gray image
        grayImg.Draw(new Ellipse(new PointF(200,200),new SizeF(100,100),0), new Gray(255.0), -1);
        // inner circle on gray image to create a donut shape :-)
        grayImg.Draw(new Ellipse(new PointF(200, 200), new SizeF(50, 50), 0), new Gray(0), -1);

        // this is the center point we'll use to initialize our contour points
        Point center = new Point(200, 200);
        // radius of polar points
        double radius = 70;

        using (MemStorage stor = new MemStorage())
        {

            Seq<Point> pts = new Seq<Point>((int)Emgu.CV.CvEnum.SEQ_TYPE.CV_SEQ_POLYGON, stor);                
            int numPoint = 100;
            for (int i = 0; i < numPoint; i++)
            {   // let's have some fun with polar coordinates                                
                Point pt = new Point((int)(center.X + (radius * Math.Cos(2 * Math.PI * i / numPoint))), (int)(center.Y + (radius * Math.Sin(2 * Math.PI * i / numPoint))) );
                pts.Push(pt);                                            
            }
            // draw contour points on result image
            img.Draw(pts, new Bgr(Color.Green), 2);
            // compute snakes                                
            Seq<Point> snake = grayImg.Snake(pts, 1.0f, 1.0f, 1.0f, new Size(21, 21), new MCvTermCriteria(100, 0.0002), stor);
            // draw snake result
            img.Draw(snake, new Bgr(Color.Yellow), 2);

            // use for display in a winform sample
            imageBox1.Image = grayImg;
            imageBox2.Image = img;
        }
    }

希望这对你有所帮助,只要改变一些参数,你就会对结果感到惊讶。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22699901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档