类型或名称空间定义,或期望的文件结束


 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using Emgu.CV;
 using Emgu.CV.Structure;
 using Emgu.Util;
 namespace ImageCapture
 {
     public partial class Form1 : Form
     {
        private Capture capture;        
        private bool captureInProgress;
        public Form1()
        {
            private void ProcessFrame(object sender, EventArgs arg)
            {
                Image<Bgr, Byte> ImageFrame = capture.QueryFrame();  
                CamImageBox.Image = ImageFrame;       
            }
            private void strat_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)
                    {  
                        btnStart.Text = "Start!"; 
                        Application.Idle -= ProcessFrame;
                    }
                    else
                    {
                        btnStart.Text = "Stop";
                        Application.Idle += ProcessFrame;
                    }
                    captureInProgress = !captureInProgress;
                } 
            }
            private void ReleaseData()
            {
                if (capture != null)
                    capture.Dispose();
            }
        }
    }
}

此代码不执行一些错误"类型或名称空间定义,或文件结束预期",禁用通过相机捕获图片。这段代码是用c#编写的,使用opencv

不能在构造函数中声明方法!

如果您的代码没有任何其他问题,那么这应该可以工作:

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using Emgu.CV;
 using Emgu.CV.Structure;
 using Emgu.Util;
 namespace ImageCapture
 {
    public partial class Form1 : Form
    {
        private Capture capture;        
        private bool captureInProgress;
        public Form1()
        {
        }
        private void ProcessFrame(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> ImageFrame = capture.QueryFrame();  
            CamImageBox.Image = ImageFrame;       
        }
        private void strat_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)
                {  
                    btnStart.Text = "Start!"; 
                    Application.Idle -= ProcessFrame;
                }
                else
                {
                    btnStart.Text = "Stop";
                    Application.Idle += ProcessFrame;
                }
                captureInProgress = !captureInProgress;
            } 
        }
        private void ReleaseData()
        {
            if (capture != null)
                capture.Dispose();
        }
    }
 }

相关内容

  • 没有找到相关文章

最新更新