2013-08-04 118 views
0

我一直在測試和搜索的幫助,但未能解決此問題:Emgu CV問題與短代碼

在C#中,並與emgu我不能運行這個簡單的代碼:

... //**after these 3 dots HERE I GOT THE FIRST WARNING :a namespace cannot directly contain members such as fields or methods** 

//Create an image of 400x200 of Blue color 
using (Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0))) 
{ 
    //Create the font 
    MCvFont f = new MCvFont(CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0); 

    //Draw "Hello, world." on the image using the specific font 
    img.Draw("Hello, world", ref f, new Point(10, 80), new Bgr(0, 255, 0)); 

    //Show the image using ImageViewer from Emgu.CV.UI 
    ImageViewer.Show(img, "Test Window"); 
} 

我得到這些錯誤:

error CS0116: A namespace cannot directly contain members such as fields or methods 
error CS1518: Expected class, delegate, enum, interface, or struct 

PS: emgu CV已正確安裝,在C#代碼(更復雜)運行完美:

namespace CameraCapture 
{ 
    public partial class CameraCapture : Form 
    { 
     //declaring global variables 
     private Capture capture;  //takes images from camera as image frames 
     private bool captureInProgress; 

     public CameraCapture() 
     { 
      InitializeComponent(); 
     } 
     //------------------------------------------------------------------------------// 
     //Process Frame() below is our user defined function in which we will create an EmguCv 
     //type image called ImageFrame. capture a frame from camera and allocate it to our 
     //ImageFrame. then show this image in ourEmguCV imageBox 
     //------------------------------------------------------------------------------// 
     private void ProcessFrame(object sender, EventArgs arg) 
     { 
      Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); 
      CamImageBox.Image = ImageFrame; 
     } 

     //btnStart_Click() function is the one that handles our "Start!" button' click 
     //event. it creates a new capture object if its not created already. e.g at first time 
     //starting. once the capture is created, it checks if the capture is still in progress, 
     //if so the 
     private void btnStart_Click(object sender, EventArgs e) 
     { 
      #region if capture is not created, create it now 
      if (capture == null) 
      { 
       try 
       { 
        capture = new Capture(); 
       } 
       catch (NullReferenceException excpt) 
       { 
        MessageBox.Show(excpt.Message); 
       } 
      } 
      #endregion 

      if (capture != null) 
      { 
       if (captureInProgress) 
       { //if camera is getting frames then stop the capture and set button Text 
        // "Start" for resuming capture 
        btnStart.Text = "Start!"; // 
        Application.Idle -= ProcessFrame; 
       } 
       else 
       { 
        //if camera is NOT getting frames then start the capture and set button 
        // Text to "Stop" for pausing capture 
        btnStart.Text = "Stop"; 
        Application.Idle += ProcessFrame; 
       } 

       captureInProgress = !captureInProgress; 
      } 
     } 

     private void ReleaseData() 
     { 
      if (capture != null) 
       capture.Dispose(); 
     } 

     private void CameraCapture_Load(object sender, EventArgs e) 
     { 

     } 
    } 
} 

謝謝你的幫助!

回答

0

也許你的命名空間名稱是一樣的,有些類或結構不同因而與命名空間

評論全部使用*碰撞,並使用全名限定符(如的System.Console.WriteLine()...)那麼它應該正常運行(如果這是一個問題)。