Use AForge. NET for video collection and aforge.net for video collection

Source: Internet
Author: User

Use AForge. NET for video collection and aforge.net for video collection

AForge. NET is designed based on C # And has powerful functions in computer vision and AI. Btw... it's an open source framework. Attached to the official website address: http://www.aforgenet.com/aforge/framework.

Today we will introduce the Video Acquisition Function in AForge. The video here includes inputs from cameras and other devices and inputs from video files.

First, let's take a look at the video source PLAYER: VideoSourcePlayer. Videos input from cameras and files are played through it and Bitmap data is output by Frame.

VideoSourcePlayer has the following important steps:

  • Initialize it and set the VideoSource attribute. VideoSource accepts parameters of the IVideoSource type, which correspond to the camera input and file input. We will set them to VideoCaptureDevice and FileVideoSource respectively.
  • Register the NewFrame event and start playing. Process Bitmap of each frame in the event registered with NewFrame.
  • After processing, cancel the NewFrame event registration and stop it. Use SignalToStop (); and WaitForStop ();

The entire process is very simple. Let's take a look at the camera input and file input code:

1. Camera Input

The first is initialization and start:

// Get the video input device list FilterInfoCollection devices = new FilterInfoCollection (FilterCategory. videoInputDevice); // obtain the first video device (the sample code does not process the number of devices is 0) VideoCaptureDevice source = new VideoCaptureDevice (devices [0]. monikerString); // set the Frame size and ratesource. desiredFrameSize = new Size (640,360); source. desiredFrameRate = 1; // set VideoSourcePlayer's VideoSourceVideoSourcePlayer videoPlayer = new VideoSourcePlayer (); videoPlayer. videoSource = source; videoPlayer. newFrame + = videoPlayer_NewFrame; videoPlayer. start ();

Here is the NewFrame Event code:

private void videoPlayer_NewFrame(object sender, ref Bitmap image){    // do sth with image    ...}

Code to stop after use:

videoPlayer.NewFrame -= videoPlayer_NewFrame;videoPlayer.SignalToStop();videoPlayer.WaitForStop();

 

2. file input

The first is initialization and start:

// The live video path file is used as the video source FileVideoSource videoSource = new FileVideoSource (videoFilePath); videoPlayer. VideoSource = videoSource; videoPlayer. NewFrame + = videoPlayer_NewFrame; videoPlayer. Start ();

The remaining two parts of the Code are the same as those entered by the camera.

For file input, note that codec on some machines is incomplete, which causes FileVideoSource to read some formats. For example, a read error occurs during mp4. In this case, you need to install a codec pack, you can.

Now, AForge. NET's video collection function is fully introduced. Next we will introduce some interesting functions in AForge.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.