最近接触的项目,使用了大量图片和视频操作,其中wpf aforge的使用遇到很多问题。本站将慢慢和大家分享
1、获取边缘点方法:
///
/// 边缘点越多,图像越清晰
///
///
///
public int Get边缘点数量(System.Drawing.Bitmap source)
{
try
{
AForge.Imaging.SusanCornersDetector mcd = new AForge.Imaging.SusanCornersDetector();
List
return corners.Count();
}
catch
{
AForge.Imaging.MoravecCornersDetector mcd = new AForge.Imaging.MoravecCornersDetector();
List
return corners.Count();
}
}
2、使用aforge自带的动态视频展示视频
///
/// 加载默认设备
///
public void cameraOpen()
{
CloseCaptureDevice();
// 设定初始视频设备
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count > 0)
{
for (int i = 0; i < videoDevices.Count; i++)
{
if (videoDevices[i].Name.IndexOf("YW") > -1)
{
DeviceMoniker = videoDevices[i].MonikerString;
break;
}
}
//DeviceMoniker = videoDevices[0]..Name.Contains("YW").MonikerString;
// UsbVideo = new VideoCaptureDevice(videoDevices[0].MonikerString);
// camera_Chemistry.vp.videoMonkeyName = videoDevices[0].MonikerString;
UsbVideo = new VideoCaptureDevice(DeviceMoniker);
camera_Chemistry.vp.videoMonkeyName = DeviceMoniker;
//sourcePlayer.NewFrame -= new AForge.Controls.VideoSourcePlayer.NewFrameHandler(videoSourcePlayer_NewFrame);
//sourcePlayer.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(videoSourcePlayer_NewFrame);
UsbVideo.VideoResolution = UsbVideo.VideoCapabilities.Where(a => a.FrameSize.Width == 640 && a.FrameSize.Height == 480).FirstOrDefault();
//UsbVideo.SnapshotFrame += UsbVideo_SnapshotFrame;
UsbVideo.NewFrame += UsbVideo_NewFrame; //截图
sourcePlayer.VideoSource = UsbVideo;
// sourcePlayer.Start();
}
else
{
//button_Play.IsEnabled = false;
//button_Capture.IsEnabled = false;
}
//设置相机摄像机的属性,亮度 对比度
GaobeijingCamera();
this电机状态 = 1; //5
}
private void CloseCaptureDevice()
{
if (sourcePlayer != null && sourcePlayer.VideoSource != null)
{
if (sourcePlayer.IsRunning)
{
sourcePlayer.SignalToStop();
sourcePlayer.WaitForStop();
sourcePlayer.Stop();
}
sourcePlayer.VideoSource = null;
if (UsbVideo.ProvideSnapshots)
{
// UsbVideo.SnapshotFrame -= new NewFrameEventHandler(UsbVideo_SnapshotFrame);
}
}
}
得到图片:
private void UsbVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// ShowSnapshot((System.Drawing.Bitmap)eventArgs.Frame); //.Clone()
ShowSnapshot(eventArgs);
}