2014-01-21 150 views
0

我固定的最後一個錯誤,這就是我的新代碼:爲「Emgu.CV.CvInvoke.cvSnakeImage的最佳重載的方法匹配具有一些無效參數

public partial class Form1 : Form 
    { 
     public Form1() 
     { 
     InitializeComponent(); 
     } 

     private void button1_Click(object sender, System.EventArgs e) 
     { 
     using (OpenFileDialog dialog = new OpenFileDialog()) 
     { 
      dialog.Filter = "JPEG|*.jpg|PNG|*.PNG"; 
      if (dialog.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; 

       Image image = Image.FromFile(dialog.FileName); 

       pictureBox1.Image = image; 

      } 
     } 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     this.Close(); 
    } 


    private void Form1_Load(object sender, EventArgs e) 
    { 

    } 
    struct parameter 
    { 
     public float alpha { get; set; } 
     public float beta { get; set; } 
     public float gamma { get; set; } 
    }; 




    unsafe private void button3_Click(object sender, EventArgs e) 
    { 
     { 

     int length = 1000; 

     Point *contour; 

     Point center = new Point(); 

     var snake_param = new List<parameter>(); 

      snake_param.Add(new parameter { alpha= 0.1f , beta = 0.1f, gamma= 0.1f, }); 

     IntPtr dst_img= new IntPtr(); 

     Bitmap bitmap = new Bitmap("pictureBox1.Image"); 

     Image<Bgr, byte> image = new Image<Bgr, byte>(bitmap); 




     center.X = image.Width; 
     center.Y = image.Height; 




     int i; 
     for (i = 0; i < length; i++) 
     { 
      contour[i].X = (int)(center.X * Math.Cos(2 * Math.PI * i/length) + center.X); 
      contour[i].Y = (int)(center.Y * Math.Sin(2 * Math.PI * i/length) + center.Y); 
     } 

    LINE_TYPE lignetype = new LINE_TYPE();   


     for (i = 0; i < length - 1; i++) 
     { 
      CvInvoke.cvLine(
       dst_img, 
       contour[i], 
       contour[i + 1], 
       new MCvScalar(255,0,0), 
       2, 
       LINE_TYPE.EIGHT_CONNECTED, 
       0 ); 
     } 


     CvInvoke.cvLine 
      (
      dst_img, 
      contour[length - 1], 
      contour[0], 
      new MCvScalar(255,0,0), 
      2, 
      LINE_TYPE.EIGHT_CONNECTED, 
      0 
      ); 


      IntPtr ctr =new IntPtr(); 
      //public void PixelToInkSpace(
      //IntPtr a 
      //ref Point contour 
      //);   



     IntPtr src_img = image.Ptr; 
     CvInvoke.cvSnakeImage(
      src_img, 
      contour[i], 
      length, 
      snake_param.[1].alfa, 
      snake_param[2].beta, 
      snake_param[3].gamma, 
      1, 
      new System.Drawing.Size(15, 15), 
      new MCvTermCriteria(1,0.0), 
      1); 



     CvInvoke.cvCvtColor(
      src_img, 
      dst_img, 
      COLOR_CONVERSION.GRAY2RGB); 


      for (i = 0; i < length - 1; i++) 
     { 
      CvInvoke.cvLine(
       dst_img, 
       contour[i], 
       contour[i + 1], 
       new MCvScalar(255,0,0), 
       2, 
       LINE_TYPE.EIGHT_CONNECTED, 
       0); 
     } 
      CvInvoke.cvLine(
       dst_img, 
       contour[length - 1], 
       contour[0], 
       new MCvScalar(255,0,0), 
        2, 
        LINE_TYPE.EIGHT_CONNECTED, 
        0); 
      pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; 

      Bitmap bitmappbb = new Bitmap("dst_img"); 
      Image<Bgr, byte> imagee = new Image<Bgr, byte>(bitmappbb); 
      pictureBox2.Image = bitmappbb; 
      } 


      } 
     } 
    } 

但現在我的錯誤是不同的,因爲我翻譯我的代碼從C++到C#, 我發現蛇格式

public static void cvSnakeImage(
IntPtr image, 
IntPtr points, 
int length, 
float[] alpha, 
float[] beta, 
float[] gamma, 
int coeffUsage, 
Size win, 
MCvTermCriteria criteria, 
bool calcGradient 

  1. 我沒有找到辦法ŧ o將類型爲「Point」的變量「contour」轉換爲「IntPtr」。
  2. 還有一種方法可以調用alfa,beta et gamma作爲float []; @Timothy沃爾特斯
+0

也許你已經張貼在其他地方,但只取了這個問題,它definetly需要更多的上下文。你的問題到底是什麼? – nvoigt

+0

我沒有找到方法來將類型爲「Point」的變量「contour」轉換爲「IntPtr」。 另一種方式稱爲阿爾法,測試和伽馬作爲浮動[]; @nvoigt – user3213662

回答

0

您需要將您的srcimg轉換爲灰度圖像比使用精明方法檢測邊緣,精明的輸出圖像。你可以得到輪廓。

下面是一些例子:

 //Canny Method 


      cannyEdges = new Image<Gray, byte>(grayImg.Size); 
         CvInvoke.cvCanny(grayImg, cannyEdges, 100, 35, 3); 
         grayImg = cannyEdges; 

     //getting contour 

     Contour<Point>[] ResultContour =new Contour<Point>[4]; 
    int c = 0; 
       for (var contours = block.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, 
        RETR_TYPE.CV_RETR_EXTERNAL); contours != null; contours = contours.HNext) 
       { 
    ResultContour[c]=contours ; 
    c++ 
    } 
相關問題