2014-03-27 4 views
1

내가 EmguCV에서 뱀 활성 윤곽을 사용하려고하고 있어요,하지만 난하지 않습니다 anything.Here 내 코드입니다 : 내가 뭘 잘못EmguCV 뱀 기능

 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); 

어떤 생각?

답변

4

초기화 포인트를 그리는 데 그리워합니다.

거기에 엠파이어 샘플이 없기 때문에 나는 당신과 전체 커뮤니티를 위해 몇 가지 코드를 설정했습니다.

 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; 
     } 
    } 

희망 사항이 도움이 되었기 때문에 일부 매개 변수 만 변경하면 결과가 놀라실 것입니다.

Snake Code sample result