Recently contacted projects, using a large number of pictures and video operations, where the use of WPF Aforge encountered many problems. This site will slowly share with you
1, Get edge point method:
<summary>
The more edge points, the clearer the image
</summary>
<param name= "source" ></param>
<returns></returns>
public int Get Edge point number (System.Drawing.Bitmap source)
{
Try
{
AForge.Imaging.SusanCornersDetector mcd = new AForge.Imaging.SusanCornersDetector ();
List<aforge.intpoint> Corners = mcd. Processimage (source);
Return corners. Count ();
}
Catch
{
AForge.Imaging.MoravecCornersDetector mcd = new AForge.Imaging.MoravecCornersDetector ();
List<aforge.intpoint> Corners = mcd. Processimage (source);
Return corners. Count ();
}
}
2, the use of aforge with the dynamic video display video
<summary>
Load Default Device
</summary>
public void Cameraopen ()
{
Closecapturedevice ();
Set the initial video device
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; Screenshots
Sourceplayer.videosource = Usbvideo;
Sourceplayer.start ();
}
Else
{
button_play.isenabled = false;
button_capture.isenabled = false;
}
Set the camera's properties, brightness contrast
Gaobeijingcamera ();
This motor state = 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);
}
}
}
Get Pictures:
private void Usbvideo_newframe (object sender, Newframeeventargs eventArgs)
{
//Showsnapshot ( SYSTEM.DRAWING.BITMAP) eventargs.frame); //. Clone ()
showsnapshot (EventArgs);
}