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

时间:2016-08-18 15:55:34

标签: 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();
            }
        }
    }
}

此代码未执行某些错误&#34;类型或命名空间定义,或期望的文件结尾&#34;禁用通过相机捕获图片。 此代码使用opencv

在c#windows应用程序中编写

1 个答案:

答案 0 :(得分:1)

你没有在构造函数中声明方法!

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

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