【发布时间】:2015-08-07 20:20:21
【问题描述】:
我正在尝试在 windows x64Bit 上使用c# 制作一个简单的openCV 相机应用程序。
为此,我将cvextern.dll、Emgu.CV.dll、Emgu.CV.UI.dll、Emgu.Util.dll 和所有opencv_*.dll 文件复制到了解决方案的调试文件夹中。
我添加文件Emgu.CV.dll、Emgu.CV.UI.dll 和Emgu.Util.dll 作为参考。
在CameraCapture 的表单中,当我单击按钮btnStart 时,相机帧应显示在图像框CamImageBox 中。
这是我的代码
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 CameraCapture
{
public partial class CameraCapture : Form
{
private Capture capture;
private bool captureInProgress;
public CameraCapture()
{
InitializeComponent();
}
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
CamImageBox.Image = ImageFrame;
}
private void btnStart_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();
}
}
}
此代码在构建项目时未显示任何错误。问题是,当我运行项目并按下按钮 btnStart 时,Imagebox CamImageBox 中没有显示任何内容。
代码显示没有错误。相机工作正常。当我运行项目时,我的相机灯亮了“当我运行项目时相机开始工作”但是我在 Imagebox 中没有收到任何图片。
文件、项目配置中是否缺少我的东西?
【问题讨论】:
-
您遗漏了一些东西?您需要添加更多内容,例如检测相机、初始化
d://show将其转换为 ImageShource/BitMapSource(在 ImageBox 中显示)或从那里捕获帧。