2011-12-17 50 views
0

我想使用由emgucv.I提供的分水岭功能使用下面的代码,但我得到的只是一张白色的图片。请帮助我并更正此代码。谢谢。由EmguCv提供的分水岭功能

Image im; 
    Bitmap bm; 
    Bitmap bmF; 
    private void button1_Click(object sender, EventArgs e)//setting the background image 
    { 
     if (openFileDialog1.ShowDialog() == DialogResult.OK) 
     { 
      im = Image.FromFile(openFileDialog1.FileName); 
      bm = new Bitmap(im); 

     } 
     panel1.BackgroundImage = im; 
     panel1.Width = im.Width; 
     panel1.Height = im.Height; 
     panel1.Visible = true; 


    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     watershed(bm); 
    } 

    private void watershed(Bitmap bm) 
    { 
     Image<Bgr, Byte> imWa = new Image<Bgr, byte>(bm); 
     Image<Gray, Int32> imgr = new Image<Gray, int>(imWa.Width, imWa.Height); 
     Rectangle rec = imWa.ROI; 
     imgr.Draw(new CircleF(new PointF(rec.Left + rec.Width/2.0f, rec.Top + rec.Height/2.0f), (float)(Math.Min(imWa.Width, imWa.Height)/4.0f)), new Gray(255), 0); 
     CvInvoke.cvWatershed(imWa, imgr); 
     bmF=new Bitmap(bm.Width,bm.Height); 
     bmF= imgr.ToBitmap(); 
     panel1.BackgroundImage = (Image)bmF; 
     panel1.Invalidate(); 
    } 
+0

你包括什么标题来获得'Bitmap'数据类型? – solvingPuzzles 2012-10-15 03:31:15

回答

1

相反的:

bmF= imgr.ToBitmap(); 

试试这个:

bmF= imgr.Convert<Gray,byte>().ToBitmap(); 
2

你需要更好地准备你的面具文件流域(即IMGR)。

为此,您需要先将所有设置为零。你可以通过调用:

CvInvoke.cvZero(imgr); 

那么你应该引入至少第二个“类”。因此,你可以用不同的坐标绘制第二个圆圈(属于背景的东西)。为了安全起见,对第一个圆圈(例如new Gray(100))使用与第二个圆圈不同的灰度值(例如new Gray(200))。

您将在最后的面具文件imgr中得到您的结果,两个类以不同的灰色值显示。

我不太确定你需要ROI位...