我是新手并且有一份工作来构建软件以创建一个程序来记录来自USB摄像头的视频并将其保存到硬盘驱动器中。如果我用-1替换fourcc方法并使用.avi文件扩展名,我设法让对话框工作。正在创建文件,但记录不存在,文件大小保持为0kb。不知道该怎么办我的代码:
私人Emgu.CV.Capture捕获;
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
//------------------------------------------------------------------------------//
VideoWriter writer;
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
CamImageBox.Image = ImageFrame;
writer = new VideoWriter(@"C:\Video.mpeg", CvInvoke.CV_FOURCC('L','M','P','2'), (int)Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS, (int)Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, (int)Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, true);
}
//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 Emgu.CV.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();
}
我在使用消息框时发现了我的问题。结果是ProcessFrame继续工作,所以我做了一些改变。这是我的新code.private Emgu.CV.Capture捕获;
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
//------------------------------------------------------------------------------//
VideoWriter writer;
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
CamImageBox.Image = ImageFrame;
writer.WriteFrame(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 Emgu.CV.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!"; //
writer.Dispose();
writer = null;
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";
writer = new VideoWriter(@"C:\Video.avi", -1, (int)Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS, 640,480, true);
Application.Idle += ProcessFrame;
}
captureInProgress = !captureInProgress;
}
}
private void ReleaseData()
{
if (capture != null)
{
writer.Dispose();
writer = null;
capture.Dispose();
}
}