0

我在 emgu cv 中为相机编写了代码,没有出现错误,但是当我按下开始按钮时,相机正在启动,但没有捕获图像。正在捕获其他项目图像。非常感谢您的帮助。

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.CV.Util;

   namespace camstop
 {
       public partial class cameracapture : Form
    {
          private Capture capture;
           private bool captureinprogress;

    public cameracapture()
    {
        InitializeComponent();
    }

    private void processFrame(object sender, EventArgs e)
    {
        Image<Bgr, Byte> imageframe = capture.QueryFrame();
        cameraimagebox.Image = imageframe;
        pictureBox1.Image = imageframe.ToBitmap();
        imageframe.Save(@"E:\\photo\\Mypic.jpg");

    }

    private void btnstart_Click(object sender, EventArgs e)
    {
        if (capture == null)
        {
            try
            {
                capture = new Capture();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }
        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)
    {

    }




}

}

4

1 回答 1

0

到达 click 事件并调用 btnstart 方法,用于图像框和按钮。如果问题在“form”中未找到,则更改命名空间名称并在 program.cs 中调用 form1 名称

于 2013-10-31T07:31:15.833 回答