由于C++的窗口编程太难了,本人才疏学浅,无法胜任。所以想用C#配合emgu CV做了一个简单的视觉计数,期间参考了各位大神的资料。请见谅。
using AForge.Video.DirectShow;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public ImageViewer viewer = new ImageViewer();//读取视频
public VideoCapture capture = new VideoCapture(); //视频帧率
public FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
public VideoCaptureDevice videoSource = new VideoCaptureDevice();
public Mat srcc = new Mat();
//private NewFrameEventHandler videoSource_NewFrame;
public Form1()
{
InitializeComponent();
GetDevices();
}
public FilterInfoCollection GetDevices()
{
try
{
//枚举所有视频输入设备
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count != 0)
{
//MessageBox.Show("已找到视频设备.");
foreach (FilterInfo device in videoDevices)
{
cbCapture.Items.Add(device.Name);//把所有的视频设备添加到下拉框中
}
cbCapture.SelectedIndex = 0;
return videoDevices;
}
else
MessageBox.Show("error:没有找到视频设备!具体原因:");
return null;
}
catch (Exception ex)
{
MessageBox.Show("error:没有找到视频设备!具体原因:", ex.Message);
return null;
}
}
private void Counter(Mat src)
{
Mat src_binary = new Mat(), dst = new Mat(), src_distance = new Mat();
//CvInvoke.Imshow("y