我在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)
{
}
}
}
答案 0 :(得分:0)
获取click事件并调用btnstart方法,用于imagebox和button .. 如果问题在“form”中找不到,则更改命名空间名称并在program.cs中调用form1名称