2013年4月8日 星期一

在 Windows XP 安裝 AForge 2.2.4 使用 C# 作 WebCam 篇程

在 Windows XP 安裝 AForge 2.2.4 使用 C# 作 WebCam 篇程: 

AForge.NET 是計算機視覺和人工智能庫 (Library),最初是由 Andrew Kirillov 為 .NET Framework 框架開發,包括電腦視覺與人工智慧,圖像處理,神經網路,遺傳演算法,機器學習,模糊系統,機器人控制等領域,AForge.NET 的源代碼和二進制文件是基於 LGPLv3 許可證的條款下提供。

AForge.NET
AForge.NET庫主要包括有:
AForge.Imaging — 一些日常的圖像處理和篩檢程式
AForge.Vision — 電腦視覺應用類庫
AForge.Neuro — 神經網路計算庫 AForge.Genetic -進化演算法編程庫
AForge.MachineLearning — 機器學習類庫
AForge.Robotics — 提供一些機器學習的工具類庫
AForge.Video — 一系列的視頻處理類庫
AForge.Fuzzy — 模糊推理系統類庫
AForge.Controls — 圖像,三維,圖表顯示控制項
 
Step by Step:
步驟 1:在網站下載 AForge.NET Framework-2.2.4.zip,下載後檔案大小 34.8MB,解壓後檔案大約 61.7MB。


  下載 AForge.NET Framework-2.2.4.zip 檔案 

步驟 2:將下載 AForge.NET Framework-2.2.4.zip 的檔案解壓到 C:\ AForge224 

步驟 3:在 Visual Studio 2010 中建立 Visual C# Windows Form 應用程式
應用程式設定(名稱:01_AForge_webcam)

Visual Studio 2010 → 檔案 → 新增 → 專案
Visual C# → Windows Form應用程式 → 專案名稱(01_AForge_webcam)→ 確定
顯示 Form 1
專案 → 加入參考
選擇 AForge.Video.DirectShow.dll 和 AForge.Video.dll → 確定
在參考的檔案夾出現AForge.Video.DirectShow.dll 和 AForge.Video.dll
選擇工具箱 → 選擇 PictureBox → PictureBox放在 Form 1
工具箱 → 選擇 Biutton → Button 放在 Form 1下面
按鼠標右鍵 → 檢視程式碼 (F7)
鍵入程式碼
01_AForge_webcam CSharp Form1.cs 程式:
// Form1.cs

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 AForge.Video;
using AForge.Video.DirectShow;

namespace _01_AForge_webcam
{
    public partial class Form1 : Form
    {
        public VideoCaptureDevice cam = null;
        public FilterInfoCollection usbCams;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cam.Stop();
        }

        void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            usbCams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            cam = new VideoCaptureDevice(usbCams[0].MonikerString);
            cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
            cam.Start();
        }   
     }
}

更改 Button1 和 Button 2 的名稱
連接 Webcam 在電腦的 USB 上

偵錯 → 開始偵錯(F5)
出現 Webcam 圖像
參考網址: 

2013 年4月8日 天氣報告
氣溫:19.2 度 @ 19:50
相對濕度:百分之79%
天氣:多雲

沒有留言:

張貼留言