2017-08-03 12 views
0

AForge.netフレームワークを使用して簡単な動き検出プログラムを作成しようとしています。 AForgeのウェブサイトでこのようなプログラムの一例であるが、それはかなり曖昧だ:モーションディテクタオブジェクトにフレームを送る方法AForge.net?

// create motion detector 
MotionDetector detector = new MotionDetector(
    new SimpleBackgroundModelingDetector(), 
    new MotionAreaHighlighting()); 

// continuously feed video frames to motion detector 
while (...) 
{ 
    // process new video frame and check motion level 
    if (detector.ProcessFrame(videoFrame) > 0.02) 
    { 
     // ring alarm or do something else 
    } 
} 

私はビデオフレームを供給する方法について解決策を見つけることができないとして、私は、whileループの条件でいくつかの助けが必要MotionDetectorオブジェクトに追加します。

ありがとうございました。

答えて

0

AForgeのDirectShow VideoInputDeviceを利用したいと思うでしょう。 whileループの代わりに、動き検出器を制御するNewFrameイベントがあります。

まず、あなたは参照が必要になります:

using AForge.Video.DirectShow; 
using AForge.Video; 
using AForge.Vision.Motion; 
using System.Drawing; 

次はあなたのキャプチャデバイスを、例えば取得する必要がありますウェブカメラやデバイスのためのNEWFRAMEイベントに新しいフレームのイベントハンドラを追加します。

Cameras = new FilterInfoCollection(FilterCategory.VideoInputDevice); 
VideoCaptureDevice Camera = new VideoCaptureDevice(Cameras[0].MonikerString); 
Camera.NewFrame += new NewFrameEventHandler(ProcessNewFrame); 

を選択するしかし今、あなたはNewFrameEventHandlerを実装できます。

private void ProcessNewFrame(object sender, NewFrameEventArgs eventArgs) 
{ 
    Bitmap frame = (Bitmap) eventArgs.Frame.Clone(); 
    if (detector.ProcessFrame(frame) > 0.02) 
    { 
     // ring alarm or do somethng else 
    } 
} 
+0

は、あなたがこれ以上の支援が必要な場合は、私に教えてください。私はちょうどAForgeベースのモーショントラッカープロジェクトを自分で完成させました。 – Iridium237

関連する問題